Skip to content

Commit

Permalink
Separate interfaces from implementations for exported classes
Browse files Browse the repository at this point in the history
= 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.
  • Loading branch information
yaacovCR committed May 29, 2022
1 parent fe8b664 commit eb98ae0
Show file tree
Hide file tree
Showing 70 changed files with 1,712 additions and 1,231 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ import {
GraphQLString,
} from 'graphql';

var schema = new GraphQLSchema({
query: new GraphQLObjectType({
var schema = new GraphQLSchemaImpl({
query: new GraphQLObjectTypeImpl({
name: 'RootQueryType',
fields: {
hello: {
Expand Down
36 changes: 18 additions & 18 deletions docs-old/APIReference-GraphQL.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ _Schema_

<ul class="apiIndex">
<li>
<a href="../type/#graphqlschema">
<pre>class GraphQLSchema</pre>
<a href="../type/#graphqlschemaimpl">
<pre>class GraphQLSchemaImpl</pre>
A representation of the capabilities of a GraphQL Server.
</a>
</li>
Expand All @@ -43,50 +43,50 @@ _Type Definitions_

<ul class="apiIndex">
<li>
<a href="../type/#graphqlscalartype">
<pre>class GraphQLScalarType</pre>
<a href="../type/#graphqlscalartypeimpl">
<pre>class GraphQLScalarTypeImpl</pre>
A scalar type within GraphQL.
</a>
</li>
<li>
<a href="../type/#graphqlobjecttype">
<pre>class GraphQLObjectType</pre>
<a href="../type/#graphqlobjecttypeimpl">
<pre>class GraphQLObjectTypeImpl</pre>
An object type within GraphQL that contains fields.
</a>
</li>
<li>
<a href="../type/#graphqlinterfacetype">
<pre>class GraphQLInterfaceType</pre>
<a href="../type/#graphqlinterfacetypeimpl">
<pre>class GraphQLInterfaceTypeImpl</pre>
An interface type within GraphQL that defines fields implementations will contain.
</a>
</li>
<li>
<a href="../type/#graphqluniontype">
<pre>class GraphQLUnionType</pre>
<a href="../type/#graphqluniontypeimpl">
<pre>class GraphQLUnionTypeImpl</pre>
A union type within GraphQL that defines a list of implementations.
</a>
</li>
<li>
<a href="../type/#graphqlenumtype">
<pre>class GraphQLEnumType</pre>
<a href="../type/#graphqlenumtypeimpl">
<pre>class GraphQLEnumTypeImpl</pre>
An enum type within GraphQL that defines a list of valid values.
</a>
</li>
<li>
<a href="../type/#graphqlinputobjecttype">
<pre>class GraphQLInputObjectType</pre>
<a href="../type/#graphqlinputobjecttypeimpl">
<pre>class GraphQLInputObjectTypeImpl</pre>
An input object type within GraphQL that represents structured inputs.
</a>
</li>
<li>
<a href="../type/#graphqllist">
<pre>class GraphQLList</pre>
<a href="../type/#graphqllistimpl">
<pre>class GraphQLListImpl</pre>
A type wrapper around other types that represents a list of those types.
</a>
</li>
<li>
<a href="../type/#graphqlnonnull">
<pre>class GraphQLNonNull</pre>
<a href="../type/#graphqlnonnullimpl">
<pre>class GraphQLNonNullImpl</pre>
A type wrapper around other types that represents a non-null version of those types.
</a>
</li>
Expand Down
16 changes: 3 additions & 13 deletions docs-old/APIReference-Language.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: graphql/language
layout: ../_core/GraphQLJSLayout
category: API Reference
permalink: /graphql-js/language/
sublinks: BREAK,getLocation,Kind,lex,parse,parseValue,printSource,visit
sublinks: getLocation,Kind,lex,parse,parseValue,printSource,visit
next: /graphql-js/type/
---

Expand Down Expand Up @@ -76,12 +76,6 @@ _Visitor_
A general-purpose visitor to traverse a parsed GraphQL AST
</a>
</li>
<li>
<a href="#break">
<pre>var BREAK</pre>
A token to allow breaking out of the visitor.
</a>
</li>
</ul>

_Printer_
Expand Down Expand Up @@ -215,15 +209,15 @@ visit function.

```js
var editedAST = visit(ast, {
enter(node, key, parent, path, ancestors) {
enter(node, key, parent, path, ancestors, BREAK) {
// @return
// undefined: no action
// false: skip visiting this node
// visitor.BREAK: stop visiting altogether
// null: delete this node
// any value: replace this node with the returned value
},
leave(node, key, parent, path, ancestors) {
leave(node, key, parent, path, ancestors, BREAK) {
// @return
// undefined: no action
// false: no action
Expand Down Expand Up @@ -295,10 +289,6 @@ visit(ast, {
});
```
### BREAK
The sentinel `BREAK` value described in the documentation of `visitor`.
## Printer
### print
Expand Down
72 changes: 36 additions & 36 deletions docs-old/APIReference-TypeSystem.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ title: graphql/type
layout: ../_core/GraphQLJSLayout
category: API Reference
permalink: /graphql-js/type/
sublinks: getNamedType,getNullableType,GraphQLBoolean,GraphQLEnumType,GraphQLFloat,GraphQLID,GraphQLInputObjectType,GraphQLInt,GraphQLInterfaceType,GraphQLList,GraphQLNonNull,GraphQLObjectType,GraphQLScalarType,GraphQLSchema,GraphQLString,GraphQLUnionType,isAbstractType,isCompositeType,isInputType,isLeafType,isOutputType
sublinks: getNamedType,getNullableType,GraphQLBoolean,GraphQLEnumTypeImpl,GraphQLFloat,GraphQLID,GraphQLInputObjectTypeImpl,GraphQLInt,GraphQLInterfaceTypeImpl,GraphQLListImpl,GraphQLNonNullImpl,GraphQLObjectTypeImpl,GraphQLScalarTypeImpl,GraphQLSchemaImpl,GraphQLString,GraphQLUnionTypeImpl,isAbstractType,isCompositeType,isInputType,isLeafType,isOutputType
next: /graphql-js/utilities/
---

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:

```js
import { GraphQLSchema } from 'graphql'; // ES6
var { GraphQLSchema } = require('graphql'); // CommonJS
import { GraphQLSchemaImpl } from 'graphql'; // ES6
var { GraphQLSchemaImpl } = require('graphql'); // CommonJS
```

## Overview
Expand All @@ -20,8 +20,8 @@ _Schema_

<ul class="apiIndex">
<li>
<a href="#graphqlschema">
<pre>class GraphQLSchema</pre>
<a href="#graphqlschemaimpl">
<pre>class GraphQLSchemaImpl</pre>
A representation of the capabilities of a GraphQL Server.
</a>
</li>
Expand All @@ -31,50 +31,50 @@ _Definitions_

<ul class="apiIndex">
<li>
<a href="#graphqlscalartype">
<pre>class GraphQLScalarType</pre>
<a href="#graphqlscalartypeimpl">
<pre>class GraphQLScalarTypeImpl</pre>
A scalar type within GraphQL.
</a>
</li>
<li>
<a href="#graphqlobjecttype">
<pre>class GraphQLObjectType</pre>
<a href="#graphqlobjecttypeimpl">
<pre>class GraphQLObjectTypeImpl</pre>
An object type within GraphQL that contains fields.
</a>
</li>
<li>
<a href="#graphqlinterfacetype">
<pre>class GraphQLInterfaceType</pre>
<a href="#graphqlinterfacetypeimpl">
<pre>class GraphQLInterfaceTypeImpl</pre>
An interface type within GraphQL that defines fields implementations will contain.
</a>
</li>
<li>
<a href="#graphqluniontype">
<pre>class GraphQLUnionType</pre>
<a href="#graphqluniontypeimpl">
<pre>class GraphQLUnionTypeImpl</pre>
A union type within GraphQL that defines a list of implementations.
</a>
</li>
<li>
<a href="#graphqlenumtype">
<pre>class GraphQLEnumType</pre>
<a href="#graphqlenumtypeimpl">
<pre>class GraphQLEnumTypeImpl</pre>
An enum type within GraphQL that defines a list of valid values.
</a>
</li>
<li>
<a href="#graphqlinputobjecttype">
<pre>class GraphQLInputObjectType</pre>
<a href="#graphqlinputobjecttypeimpl">
<pre>class GraphQLInputObjectTypeImpl</pre>
An input object type within GraphQL that represents structured inputs.
</a>
</li>
<li>
<a href="#graphqllist">
<pre>class GraphQLList</pre>
<a href="#graphqllistimpl">
<pre>class GraphQLListImpl</pre>
A type wrapper around other types that represents a list of those types.
</a>
</li>
<li>
<a href="#graphqlnonnull">
<pre>class GraphQLNonNull</pre>
<a href="#graphqlnonnullimpl">
<pre>class GraphQLNonNullImpl</pre>
A type wrapper around other types that represents a non-null version of those types.
</a>
</li>
Expand Down Expand Up @@ -188,7 +188,7 @@ validator and executor.
#### Example
```js
var MyAppSchema = new GraphQLSchema({
var MyAppSchema = new GraphQLSchemaImpl({
query: MyAppQueryRootType
mutation: MyAppMutationRootType
});
Expand Down Expand Up @@ -220,7 +220,7 @@ functions used to ensure validity.
#### Example
```js
var OddType = new GraphQLScalarType({
var OddType = new GraphQLScalarTypeImpl({
name: 'Odd',
serialize: oddValue,
parseValue: oddValue,
Expand Down Expand Up @@ -315,7 +315,7 @@ that value can always be referenced with `this`.
#### Examples
```js
var AddressType = new GraphQLObjectType({
var AddressType = new GraphQLObjectTypeImpl({
name: 'Address',
fields: {
street: { type: GraphQLString },
Expand All @@ -329,7 +329,7 @@ var AddressType = new GraphQLObjectType({
},
});

var PersonType = new GraphQLObjectType({
var PersonType = new GraphQLObjectTypeImpl({
name: 'Person',
fields: () => ({
name: { type: GraphQLString },
Expand Down Expand Up @@ -361,7 +361,7 @@ when the field is resolved.
#### Example
```js
var EntityType = new GraphQLInterfaceType({
var EntityType = new GraphQLInterfaceTypeImpl({
name: 'Entity',
fields: {
name: { type: GraphQLString },
Expand Down Expand Up @@ -393,7 +393,7 @@ to determine which type is actually used when the field is resolved.
### Example
```js
var PetType = new GraphQLUnionType({
var PetType = new GraphQLUnionTypeImpl({
name: 'Pet',
types: [DogType, CatType],
resolveType(value) {
Expand Down Expand Up @@ -448,7 +448,7 @@ will be used as its internal value.
#### Example
```js
var RGBType = new GraphQLEnumType({
var RGBType = new GraphQLEnumTypeImpl({
name: 'RGB',
values: {
RED: { value: 0 },
Expand Down Expand Up @@ -503,11 +503,11 @@ Using `NonNull` will ensure that a value must be provided by the query
#### Example
```js
var GeoPoint = new GraphQLInputObjectType({
var GeoPoint = new GraphQLInputObjectTypeImpl({
name: 'GeoPoint',
fields: {
lat: { type: new GraphQLNonNull(GraphQLFloat) },
lon: { type: new GraphQLNonNull(GraphQLFloat) },
lat: { type: new GraphQLNonNullImpl(GraphQLFloat) },
lon: { type: new GraphQLNonNullImpl(GraphQLFloat) },
alt: { type: GraphQLFloat, defaultValue: 0 },
},
});
Expand All @@ -528,11 +528,11 @@ an object type.
#### Example
```js
var PersonType = new GraphQLObjectType({
var PersonType = new GraphQLObjectTypeImpl({
name: 'Person',
fields: () => ({
parents: { type: new GraphQLList(Person) },
children: { type: new GraphQLList(Person) },
parents: { type: new GraphQLListImpl(Person) },
children: { type: new GraphQLListImpl(Person) },
}),
});
```
Expand All @@ -554,10 +554,10 @@ usually the id field of a database row will never be null.
#### Example
```js
var RowType = new GraphQLObjectType({
var RowType = new GraphQLObjectTypeImpl({
name: 'Row',
fields: () => ({
id: { type: new GraphQLNonNull(String) },
id: { type: new GraphQLNonNullImpl(String) },
}),
});
```
Expand Down
11 changes: 8 additions & 3 deletions integrationTests/ts/basic-test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import type { ExecutionResult } from 'graphql/execution';

import { graphqlSync } from 'graphql';
import { GraphQLString, GraphQLSchema, GraphQLObjectType } from 'graphql/type';
import {
GraphQLString,
GraphQLSchema,
GraphQLObjectTypeImpl,
} from 'graphql/type';
import type { GraphQLObjectType } from 'graphql/type';

const queryType: GraphQLObjectType = new GraphQLObjectType({
const queryType: GraphQLObjectType = new GraphQLObjectTypeImpl({
name: 'Query',
fields: () => ({
sayHi: {
Expand All @@ -21,7 +26,7 @@ const queryType: GraphQLObjectType = new GraphQLObjectType({
}),
});

const schema: GraphQLSchema = new GraphQLSchema({ query: queryType });
const schema: GraphQLSchema = new GraphQLSchemaImpl({ query: queryType });

const result: ExecutionResult = graphqlSync({
schema,
Expand Down
5 changes: 3 additions & 2 deletions integrationTests/ts/extensions-test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { GraphQLError } from 'graphql/error';
import { GraphQLString, GraphQLObjectType } from 'graphql/type';
import { GraphQLString, GraphQLObjectTypeImpl } from 'graphql/type';
import type { GraphQLObjectType } from 'graphql/type';

interface SomeExtension {
meaningOfLife: 42;
Expand All @@ -19,7 +20,7 @@ declare module 'graphql' {
}
}

const queryType: GraphQLObjectType = new GraphQLObjectType({
const queryType: GraphQLObjectType = new GraphQLObjectTypeImpl({
name: 'Query',
fields: () => ({
sayHi: {
Expand Down
Loading

0 comments on commit eb98ae0

Please sign in to comment.