-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
return internal types in schema introspection (#2773)
according to graphql spec: ``` types: return the set of all named types contained within this schema. Any named type which can be found through a field of any introspection type must be included in this set. ``` source: https://github.com/graphql/graphql-spec/blob/main/spec/Section%204%20--%20Introspection.md#the-__schema-type some clients libs (like HotChocolate for C#) depends on this behavior.
- Loading branch information
1 parent
065aea3
commit 1cde8c3
Showing
2 changed files
with
68 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package introspection | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/vektah/gqlparser/v2/ast" | ||
) | ||
|
||
func TestSchema(t *testing.T) { | ||
query := &ast.Definition{ | ||
Name: "Query", | ||
Kind: ast.Object, | ||
} | ||
|
||
mutation := &ast.Definition{ | ||
Name: "Mutation", | ||
Kind: ast.Object, | ||
} | ||
|
||
subscription := &ast.Definition{ | ||
Name: "Subscription", | ||
Kind: ast.Object, | ||
} | ||
|
||
directive := &ast.Definition{ | ||
Name: "__Directive", | ||
Kind: ast.Object, | ||
} | ||
|
||
schema := &Schema{ | ||
schema: &ast.Schema{ | ||
Query: query, | ||
Mutation: mutation, | ||
Subscription: subscription, | ||
Types: map[string]*ast.Definition{ | ||
"Query": query, | ||
"Mutation": mutation, | ||
"__Directive": directive, | ||
}, | ||
Description: "test description", | ||
}, | ||
} | ||
|
||
t.Run("description", func(t *testing.T) { | ||
require.EqualValues(t, "test description", *schema.Description()) | ||
}) | ||
|
||
t.Run("query type", func(t *testing.T) { | ||
require.Equal(t, "Query", *schema.QueryType().Name()) | ||
}) | ||
|
||
t.Run("mutation type", func(t *testing.T) { | ||
require.Equal(t, "Mutation", *schema.MutationType().Name()) | ||
}) | ||
|
||
t.Run("subscription type", func(t *testing.T) { | ||
require.Equal(t, "Subscription", *schema.SubscriptionType().Name()) | ||
}) | ||
|
||
t.Run("types", func(t *testing.T) { | ||
types := schema.Types() | ||
require.Len(t, types, 3) | ||
require.Equal(t, "Mutation", *types[0].Name()) | ||
require.Equal(t, "Query", *types[1].Name()) | ||
require.Equal(t, "__Directive", *types[2].Name()) | ||
}) | ||
} |