Skip to content

Commit e60c6f3

Browse files
committed
Separate interfaces from implementations for exported classes
= allows for cross-realm/worker GraphQL = allows for custom implementations of the GraphQL entity implementations, e.g. the `execute` function from GraphQL can be used for any object that implements the `GraphQLSchema` interface, even if does not conform to the default `GraphQLSchemaImpl` class. = currently provides symbols for predicates for the following interfaces: `GraphQLScalarType`, `GraphQLObjectType`, `GraphQLInterfaceType`, `GraphQLUnionType`, `GraphQLEnumType`, `GraphQLInputObjectType`, `GraphQLList`, `GraphQLNonNull`, `GraphQLDirective`, `GraphQLSchema`, and `Source`, i.e. all classes that made internal use of the `instanceOf` method. = the `instanceOf` method now uses symbols instead of `instanceof`. = the exported BREAK object is now passed into the visitor function to allow for cross-compatibility between `graphql` library instances.
1 parent 540bb38 commit e60c6f3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1724
-1231
lines changed

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ import {
4848
GraphQLString,
4949
} from 'graphql';
5050

51-
var schema = new GraphQLSchema({
52-
query: new GraphQLObjectType({
51+
var schema = new GraphQLSchemaImpl({
52+
query: new GraphQLObjectTypeImpl({
5353
name: 'RootQueryType',
5454
fields: {
5555
hello: {

Diff for: docs-old/APIReference-GraphQL.md

+18-18
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ _Schema_
3232

3333
<ul class="apiIndex">
3434
<li>
35-
<a href="../type/#graphqlschema">
36-
<pre>class GraphQLSchema</pre>
35+
<a href="../type/#graphqlschemaimpl">
36+
<pre>class GraphQLSchemaImpl</pre>
3737
A representation of the capabilities of a GraphQL Server.
3838
</a>
3939
</li>
@@ -43,50 +43,50 @@ _Type Definitions_
4343

4444
<ul class="apiIndex">
4545
<li>
46-
<a href="../type/#graphqlscalartype">
47-
<pre>class GraphQLScalarType</pre>
46+
<a href="../type/#graphqlscalartypeimpl">
47+
<pre>class GraphQLScalarTypeImpl</pre>
4848
A scalar type within GraphQL.
4949
</a>
5050
</li>
5151
<li>
52-
<a href="../type/#graphqlobjecttype">
53-
<pre>class GraphQLObjectType</pre>
52+
<a href="../type/#graphqlobjecttypeimpl">
53+
<pre>class GraphQLObjectTypeImpl</pre>
5454
An object type within GraphQL that contains fields.
5555
</a>
5656
</li>
5757
<li>
58-
<a href="../type/#graphqlinterfacetype">
59-
<pre>class GraphQLInterfaceType</pre>
58+
<a href="../type/#graphqlinterfacetypeimpl">
59+
<pre>class GraphQLInterfaceTypeImpl</pre>
6060
An interface type within GraphQL that defines fields implementations will contain.
6161
</a>
6262
</li>
6363
<li>
64-
<a href="../type/#graphqluniontype">
65-
<pre>class GraphQLUnionType</pre>
64+
<a href="../type/#graphqluniontypeimpl">
65+
<pre>class GraphQLUnionTypeImpl</pre>
6666
A union type within GraphQL that defines a list of implementations.
6767
</a>
6868
</li>
6969
<li>
70-
<a href="../type/#graphqlenumtype">
71-
<pre>class GraphQLEnumType</pre>
70+
<a href="../type/#graphqlenumtypeimpl">
71+
<pre>class GraphQLEnumTypeImpl</pre>
7272
An enum type within GraphQL that defines a list of valid values.
7373
</a>
7474
</li>
7575
<li>
76-
<a href="../type/#graphqlinputobjecttype">
77-
<pre>class GraphQLInputObjectType</pre>
76+
<a href="../type/#graphqlinputobjecttypeimpl">
77+
<pre>class GraphQLInputObjectTypeImpl</pre>
7878
An input object type within GraphQL that represents structured inputs.
7979
</a>
8080
</li>
8181
<li>
82-
<a href="../type/#graphqllist">
83-
<pre>class GraphQLList</pre>
82+
<a href="../type/#graphqllistimpl">
83+
<pre>class GraphQLListImpl</pre>
8484
A type wrapper around other types that represents a list of those types.
8585
</a>
8686
</li>
8787
<li>
88-
<a href="../type/#graphqlnonnull">
89-
<pre>class GraphQLNonNull</pre>
88+
<a href="../type/#graphqlnonnullimpl">
89+
<pre>class GraphQLNonNullImpl</pre>
9090
A type wrapper around other types that represents a non-null version of those types.
9191
</a>
9292
</li>

Diff for: docs-old/APIReference-Language.md

+3-13
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: graphql/language
33
layout: ../_core/GraphQLJSLayout
44
category: API Reference
55
permalink: /graphql-js/language/
6-
sublinks: BREAK,getLocation,Kind,lex,parse,parseValue,printSource,visit
6+
sublinks: getLocation,Kind,lex,parse,parseValue,printSource,visit
77
next: /graphql-js/type/
88
---
99

@@ -76,12 +76,6 @@ _Visitor_
7676
A general-purpose visitor to traverse a parsed GraphQL AST
7777
</a>
7878
</li>
79-
<li>
80-
<a href="#break">
81-
<pre>var BREAK</pre>
82-
A token to allow breaking out of the visitor.
83-
</a>
84-
</li>
8579
</ul>
8680

8781
_Printer_
@@ -215,15 +209,15 @@ visit function.
215209

216210
```js
217211
var editedAST = visit(ast, {
218-
enter(node, key, parent, path, ancestors) {
212+
enter(node, key, parent, path, ancestors, BREAK) {
219213
// @return
220214
// undefined: no action
221215
// false: skip visiting this node
222216
// visitor.BREAK: stop visiting altogether
223217
// null: delete this node
224218
// any value: replace this node with the returned value
225219
},
226-
leave(node, key, parent, path, ancestors) {
220+
leave(node, key, parent, path, ancestors, BREAK) {
227221
// @return
228222
// undefined: no action
229223
// false: no action
@@ -295,10 +289,6 @@ visit(ast, {
295289
});
296290
```
297291
298-
### BREAK
299-
300-
The sentinel `BREAK` value described in the documentation of `visitor`.
301-
302292
## Printer
303293
304294
### print

Diff for: docs-old/APIReference-TypeSystem.md

+36-36
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ title: graphql/type
33
layout: ../_core/GraphQLJSLayout
44
category: API Reference
55
permalink: /graphql-js/type/
6-
sublinks: getNamedType,getNullableType,GraphQLBoolean,GraphQLEnumType,GraphQLFloat,GraphQLID,GraphQLInputObjectType,GraphQLInt,GraphQLInterfaceType,GraphQLList,GraphQLNonNull,GraphQLObjectType,GraphQLScalarType,GraphQLSchema,GraphQLString,GraphQLUnionType,isAbstractType,isCompositeType,isInputType,isLeafType,isOutputType
6+
sublinks: getNamedType,getNullableType,GraphQLBoolean,GraphQLEnumTypeImpl,GraphQLFloat,GraphQLID,GraphQLInputObjectTypeImpl,GraphQLInt,GraphQLInterfaceTypeImpl,GraphQLListImpl,GraphQLNonNullImpl,GraphQLObjectTypeImpl,GraphQLScalarTypeImpl,GraphQLSchemaImpl,GraphQLString,GraphQLUnionTypeImpl,isAbstractType,isCompositeType,isInputType,isLeafType,isOutputType
77
next: /graphql-js/utilities/
88
---
99

1010
The `graphql/type` module is responsible for defining GraphQL types and schema. You can import either from the `graphql/type` module, or from the root `graphql` module. For example:
1111

1212
```js
13-
import { GraphQLSchema } from 'graphql'; // ES6
14-
var { GraphQLSchema } = require('graphql'); // CommonJS
13+
import { GraphQLSchemaImpl } from 'graphql'; // ES6
14+
var { GraphQLSchemaImpl } = require('graphql'); // CommonJS
1515
```
1616

1717
## Overview
@@ -20,8 +20,8 @@ _Schema_
2020

2121
<ul class="apiIndex">
2222
<li>
23-
<a href="#graphqlschema">
24-
<pre>class GraphQLSchema</pre>
23+
<a href="#graphqlschemaimpl">
24+
<pre>class GraphQLSchemaImpl</pre>
2525
A representation of the capabilities of a GraphQL Server.
2626
</a>
2727
</li>
@@ -31,50 +31,50 @@ _Definitions_
3131

3232
<ul class="apiIndex">
3333
<li>
34-
<a href="#graphqlscalartype">
35-
<pre>class GraphQLScalarType</pre>
34+
<a href="#graphqlscalartypeimpl">
35+
<pre>class GraphQLScalarTypeImpl</pre>
3636
A scalar type within GraphQL.
3737
</a>
3838
</li>
3939
<li>
40-
<a href="#graphqlobjecttype">
41-
<pre>class GraphQLObjectType</pre>
40+
<a href="#graphqlobjecttypeimpl">
41+
<pre>class GraphQLObjectTypeImpl</pre>
4242
An object type within GraphQL that contains fields.
4343
</a>
4444
</li>
4545
<li>
46-
<a href="#graphqlinterfacetype">
47-
<pre>class GraphQLInterfaceType</pre>
46+
<a href="#graphqlinterfacetypeimpl">
47+
<pre>class GraphQLInterfaceTypeImpl</pre>
4848
An interface type within GraphQL that defines fields implementations will contain.
4949
</a>
5050
</li>
5151
<li>
52-
<a href="#graphqluniontype">
53-
<pre>class GraphQLUnionType</pre>
52+
<a href="#graphqluniontypeimpl">
53+
<pre>class GraphQLUnionTypeImpl</pre>
5454
A union type within GraphQL that defines a list of implementations.
5555
</a>
5656
</li>
5757
<li>
58-
<a href="#graphqlenumtype">
59-
<pre>class GraphQLEnumType</pre>
58+
<a href="#graphqlenumtypeimpl">
59+
<pre>class GraphQLEnumTypeImpl</pre>
6060
An enum type within GraphQL that defines a list of valid values.
6161
</a>
6262
</li>
6363
<li>
64-
<a href="#graphqlinputobjecttype">
65-
<pre>class GraphQLInputObjectType</pre>
64+
<a href="#graphqlinputobjecttypeimpl">
65+
<pre>class GraphQLInputObjectTypeImpl</pre>
6666
An input object type within GraphQL that represents structured inputs.
6767
</a>
6868
</li>
6969
<li>
70-
<a href="#graphqllist">
71-
<pre>class GraphQLList</pre>
70+
<a href="#graphqllistimpl">
71+
<pre>class GraphQLListImpl</pre>
7272
A type wrapper around other types that represents a list of those types.
7373
</a>
7474
</li>
7575
<li>
76-
<a href="#graphqlnonnull">
77-
<pre>class GraphQLNonNull</pre>
76+
<a href="#graphqlnonnullimpl">
77+
<pre>class GraphQLNonNullImpl</pre>
7878
A type wrapper around other types that represents a non-null version of those types.
7979
</a>
8080
</li>
@@ -188,7 +188,7 @@ validator and executor.
188188
#### Example
189189
190190
```js
191-
var MyAppSchema = new GraphQLSchema({
191+
var MyAppSchema = new GraphQLSchemaImpl({
192192
query: MyAppQueryRootType
193193
mutation: MyAppMutationRootType
194194
});
@@ -220,7 +220,7 @@ functions used to ensure validity.
220220
#### Example
221221
222222
```js
223-
var OddType = new GraphQLScalarType({
223+
var OddType = new GraphQLScalarTypeImpl({
224224
name: 'Odd',
225225
serialize: oddValue,
226226
parseValue: oddValue,
@@ -315,7 +315,7 @@ that value can always be referenced with `this`.
315315
#### Examples
316316
317317
```js
318-
var AddressType = new GraphQLObjectType({
318+
var AddressType = new GraphQLObjectTypeImpl({
319319
name: 'Address',
320320
fields: {
321321
street: { type: GraphQLString },
@@ -329,7 +329,7 @@ var AddressType = new GraphQLObjectType({
329329
},
330330
});
331331

332-
var PersonType = new GraphQLObjectType({
332+
var PersonType = new GraphQLObjectTypeImpl({
333333
name: 'Person',
334334
fields: () => ({
335335
name: { type: GraphQLString },
@@ -361,7 +361,7 @@ when the field is resolved.
361361
#### Example
362362
363363
```js
364-
var EntityType = new GraphQLInterfaceType({
364+
var EntityType = new GraphQLInterfaceTypeImpl({
365365
name: 'Entity',
366366
fields: {
367367
name: { type: GraphQLString },
@@ -393,7 +393,7 @@ to determine which type is actually used when the field is resolved.
393393
### Example
394394
395395
```js
396-
var PetType = new GraphQLUnionType({
396+
var PetType = new GraphQLUnionTypeImpl({
397397
name: 'Pet',
398398
types: [DogType, CatType],
399399
resolveType(value) {
@@ -448,7 +448,7 @@ will be used as its internal value.
448448
#### Example
449449
450450
```js
451-
var RGBType = new GraphQLEnumType({
451+
var RGBType = new GraphQLEnumTypeImpl({
452452
name: 'RGB',
453453
values: {
454454
RED: { value: 0 },
@@ -503,11 +503,11 @@ Using `NonNull` will ensure that a value must be provided by the query
503503
#### Example
504504
505505
```js
506-
var GeoPoint = new GraphQLInputObjectType({
506+
var GeoPoint = new GraphQLInputObjectTypeImpl({
507507
name: 'GeoPoint',
508508
fields: {
509-
lat: { type: new GraphQLNonNull(GraphQLFloat) },
510-
lon: { type: new GraphQLNonNull(GraphQLFloat) },
509+
lat: { type: new GraphQLNonNullImpl(GraphQLFloat) },
510+
lon: { type: new GraphQLNonNullImpl(GraphQLFloat) },
511511
alt: { type: GraphQLFloat, defaultValue: 0 },
512512
},
513513
});
@@ -528,11 +528,11 @@ an object type.
528528
#### Example
529529
530530
```js
531-
var PersonType = new GraphQLObjectType({
531+
var PersonType = new GraphQLObjectTypeImpl({
532532
name: 'Person',
533533
fields: () => ({
534-
parents: { type: new GraphQLList(Person) },
535-
children: { type: new GraphQLList(Person) },
534+
parents: { type: new GraphQLListImpl(Person) },
535+
children: { type: new GraphQLListImpl(Person) },
536536
}),
537537
});
538538
```
@@ -554,10 +554,10 @@ usually the id field of a database row will never be null.
554554
#### Example
555555
556556
```js
557-
var RowType = new GraphQLObjectType({
557+
var RowType = new GraphQLObjectTypeImpl({
558558
name: 'Row',
559559
fields: () => ({
560-
id: { type: new GraphQLNonNull(String) },
560+
id: { type: new GraphQLNonNullImpl(String) },
561561
}),
562562
});
563563
```

Diff for: integrationTests/ts/basic-test.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import type { ExecutionResult } from 'graphql/execution';
22

33
import { graphqlSync } from 'graphql';
4-
import { GraphQLString, GraphQLSchema, GraphQLObjectType } from 'graphql/type';
4+
import type { GraphQLSchema, GraphQLObjectType } from 'graphql/type';
5+
import {
6+
GraphQLString,
7+
GraphQLSchemaImpl,
8+
GraphQLObjectTypeImpl,
9+
} from 'graphql/type';
510

6-
const queryType: GraphQLObjectType = new GraphQLObjectType({
11+
const queryType: GraphQLObjectType = new GraphQLObjectTypeImpl({
712
name: 'Query',
813
fields: () => ({
914
sayHi: {
@@ -21,7 +26,7 @@ const queryType: GraphQLObjectType = new GraphQLObjectType({
2126
}),
2227
});
2328

24-
const schema: GraphQLSchema = new GraphQLSchema({ query: queryType });
29+
const schema: GraphQLSchema = new GraphQLSchemaImpl({ query: queryType });
2530

2631
const result: ExecutionResult = graphqlSync({
2732
schema,

Diff for: integrationTests/ts/extensions-test.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { GraphQLError } from 'graphql/error';
2-
import { GraphQLString, GraphQLObjectType } from 'graphql/type';
2+
import { GraphQLString, GraphQLObjectTypeImpl } from 'graphql/type';
3+
import type { GraphQLObjectType } from 'graphql/type';
34

45
interface SomeExtension {
56
meaningOfLife: 42;
@@ -19,7 +20,7 @@ declare module 'graphql' {
1920
}
2021
}
2122

22-
const queryType: GraphQLObjectType = new GraphQLObjectType({
23+
const queryType: GraphQLObjectType = new GraphQLObjectTypeImpl({
2324
name: 'Query',
2425
fields: () => ({
2526
sayHi: {

0 commit comments

Comments
 (0)