Skip to content

Commit f1c9b82

Browse files
elevenpassinIvanGoncharov
authored andcommitted
Documentation for explicitly mentioning ObjectTypes (#1679)
* Documentation for explicitly mentioning ObjectTypes Based on the discussion at #1413 * Minor typo/fix * Edit example doc for schema definition - provide more clear example /w interfaces & types - rewrite to note with more clarity - move the note above the note on directives * clarify documentation * Remove unwanted star
1 parent e2dec84 commit f1c9b82

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/type/schema.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,43 @@ export function assertSchema(schema: mixed): GraphQLSchema {
7272
* mutation: MyAppMutationRootType,
7373
* })
7474
*
75+
* Note: When the schema is constructed, by default only the types that are
76+
* reachable by traversing the root types are included, other types must be
77+
* explicitly referenced.
78+
*
79+
* Example:
80+
*
81+
* const characterInterface = new GraphQLInterfaceType({
82+
* name: 'Character',
83+
* ...
84+
* });
85+
*
86+
* const humanType = new GraphQLObjectType({
87+
* name: 'Human',
88+
* interfaces: [characterInterface],
89+
* ...
90+
* });
91+
*
92+
* const droidType = new GraphQLObjectType({
93+
* name: 'Droid',
94+
* interfaces: [characterInterface],
95+
* ...
96+
* });
97+
*
98+
* const schema = new GraphQLSchema({
99+
* query: new GraphQLObjectType({
100+
* name: 'Query',
101+
* fields: {
102+
* hero: { type: characterInterface, ... },
103+
* }
104+
* }),
105+
* ...
106+
* // Since this schema references only the `Character` interface it's
107+
* // necessary to explicitly list the types that implement it if
108+
* // you want them to be included in the final schema.
109+
* types: [humanType, droidType],
110+
* })
111+
*
75112
* Note: If an array of `directives` are provided to GraphQLSchema, that will be
76113
* the exact list of directives represented and allowed. If `directives` is not
77114
* provided then a default set of the specified directives (e.g. @include and

0 commit comments

Comments
 (0)