Skip to content

Commit e075bec

Browse files
committed
Documentation for explicitly mentioning ObjectTypes
Replicates graphql/graphql-js@f1c9b82
1 parent 3f125a7 commit e075bec

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

graphql/type/schema.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,40 @@ class GraphQLSchema:
3737
3838
Example::
3939
40-
const MyAppSchema = GraphQLSchema(
40+
MyAppSchema = GraphQLSchema(
4141
query=MyAppQueryRootType,
4242
mutation=MyAppMutationRootType)
4343
44+
Note: When the schema is constructed, by default only the types that are
45+
reachable by traversing the root types are included, other types must be
46+
explicitly referenced.
47+
48+
Example::
49+
50+
character_interface = GraphQLInterfaceType('Character', ...)
51+
52+
human_type = GraphQLObjectType(
53+
'Human', interfaces=[character_interface], ...)
54+
55+
droid_type = GraphQLObjectType(
56+
'Droid', interfaces: [character_interface], ...)
57+
58+
schema = GraphQLSchema(
59+
query=GraphQLObjectType('Query',
60+
fields={'hero': GraphQLField(character_interface, ....)}),
61+
...
62+
# Since this schema references only the `Character` interface it's
63+
# necessary to explicitly list the types that implement it if
64+
# you want them to be included in the final schema.
65+
types=[human_type, droid_type])
66+
4467
Note: If a list of `directives` are provided to GraphQLSchema, that will be the
4568
exact list of directives represented and allowed. If `directives` is not provided,
4669
then a default set of the specified directives (e.g. @include and @skip) will be
4770
used. If you wish to provide *additional* directives to these specified directives,
4871
you must explicitly declare them. Example::
4972
50-
const MyAppSchema = GraphQLSchema(
73+
MyAppSchema = GraphQLSchema(
5174
...
5275
directives=specifiedDirectives + [myCustomDirective])
5376
"""

0 commit comments

Comments
 (0)