github.com/apipluspower/gqlgen@v0.15.2/codegen/data_test.go (about) 1 package codegen 2 3 import ( 4 "testing" 5 6 "github.com/apipluspower/gqlgen/codegen/config" 7 "github.com/vektah/gqlparser/v2/ast" 8 9 "github.com/stretchr/testify/assert" 10 ) 11 12 func TestData_Directives(t *testing.T) { 13 d := Data{ 14 Config: &config.Config{ 15 Sources: []*ast.Source{ 16 { 17 Name: "schema.graphql", 18 }, 19 }, 20 }, 21 AllDirectives: DirectiveList{ 22 "includeDirective": { 23 DirectiveDefinition: &ast.DirectiveDefinition{ 24 Name: "includeDirective", 25 Position: &ast.Position{ 26 Src: &ast.Source{ 27 Name: "schema.graphql", 28 }, 29 }, 30 }, 31 Name: "includeDirective", 32 Args: nil, 33 Builtin: false, 34 }, 35 "excludeDirective": { 36 DirectiveDefinition: &ast.DirectiveDefinition{ 37 Name: "excludeDirective", 38 Position: &ast.Position{ 39 Src: &ast.Source{ 40 Name: "anothersource.graphql", 41 }, 42 }, 43 }, 44 Name: "excludeDirective", 45 Args: nil, 46 Builtin: false, 47 }, 48 }, 49 } 50 51 expected := DirectiveList{ 52 "includeDirective": { 53 DirectiveDefinition: &ast.DirectiveDefinition{ 54 Name: "includeDirective", 55 Position: &ast.Position{ 56 Src: &ast.Source{ 57 Name: "schema.graphql", 58 }, 59 }, 60 }, 61 Name: "includeDirective", 62 Args: nil, 63 Builtin: false, 64 }, 65 } 66 67 assert.Equal(t, expected, d.Directives()) 68 }