github.com/niko0xdev/gqlgen@v0.17.55-0.20240120102243-2ecff98c3e37/graphql/introspection/type_test.go (about)

     1  package introspection
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/require"
     7  	"github.com/vektah/gqlparser/v2/ast"
     8  )
     9  
    10  func TestType(t *testing.T) {
    11  	schemaType := Type{
    12  		def: &ast.Definition{
    13  			Name:        "Query",
    14  			Description: "test description",
    15  			Fields: ast.FieldList{
    16  				&ast.FieldDefinition{Name: "__schema"},
    17  				&ast.FieldDefinition{Name: "test"},
    18  				&ast.FieldDefinition{Name: "deprecated", Directives: ast.DirectiveList{
    19  					&ast.Directive{Name: "deprecated"},
    20  				}},
    21  			},
    22  			Kind: ast.Object,
    23  		},
    24  	}
    25  
    26  	t.Run("name", func(t *testing.T) {
    27  		require.Equal(t, "Query", *schemaType.Name())
    28  	})
    29  
    30  	t.Run("description", func(t *testing.T) {
    31  		require.Equal(t, "test description", *schemaType.Description())
    32  	})
    33  
    34  	t.Run("fields", func(t *testing.T) {
    35  		fields := schemaType.Fields(false)
    36  		require.Len(t, fields, 1)
    37  		require.Equal(t, "test", fields[0].Name)
    38  	})
    39  
    40  	t.Run("fields includeDepricated", func(t *testing.T) {
    41  		fields := schemaType.Fields(true)
    42  		require.Len(t, fields, 2)
    43  		require.Equal(t, "test", fields[0].Name)
    44  		require.Equal(t, "deprecated", fields[1].Name)
    45  	})
    46  }