github.com/niko0xdev/gqlgen@v0.17.55-0.20240120102243-2ecff98c3e37/graphql/introspection/schema_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 TestSchema(t *testing.T) {
    11  	query := &ast.Definition{
    12  		Name: "Query",
    13  		Kind: ast.Object,
    14  	}
    15  
    16  	mutation := &ast.Definition{
    17  		Name: "Mutation",
    18  		Kind: ast.Object,
    19  	}
    20  
    21  	subscription := &ast.Definition{
    22  		Name: "Subscription",
    23  		Kind: ast.Object,
    24  	}
    25  
    26  	directive := &ast.Definition{
    27  		Name: "__Directive",
    28  		Kind: ast.Object,
    29  	}
    30  
    31  	schema := &Schema{
    32  		schema: &ast.Schema{
    33  			Query:        query,
    34  			Mutation:     mutation,
    35  			Subscription: subscription,
    36  			Types: map[string]*ast.Definition{
    37  				"Query":       query,
    38  				"Mutation":    mutation,
    39  				"__Directive": directive,
    40  			},
    41  			Description: "test description",
    42  		},
    43  	}
    44  
    45  	t.Run("description", func(t *testing.T) {
    46  		require.EqualValues(t, "test description", *schema.Description())
    47  	})
    48  
    49  	t.Run("query type", func(t *testing.T) {
    50  		require.Equal(t, "Query", *schema.QueryType().Name())
    51  	})
    52  
    53  	t.Run("mutation type", func(t *testing.T) {
    54  		require.Equal(t, "Mutation", *schema.MutationType().Name())
    55  	})
    56  
    57  	t.Run("subscription type", func(t *testing.T) {
    58  		require.Equal(t, "Subscription", *schema.SubscriptionType().Name())
    59  	})
    60  
    61  	t.Run("types", func(t *testing.T) {
    62  		types := schema.Types()
    63  		require.Len(t, types, 3)
    64  		require.Equal(t, "Mutation", *types[0].Name())
    65  		require.Equal(t, "Query", *types[1].Name())
    66  		require.Equal(t, "__Directive", *types[2].Name())
    67  	})
    68  }