forked from graphql/graphql-js
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix ExecutorSchema isNullType (#128)
- Loading branch information
Showing
3 changed files
with
98 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'graphql-executor': patch | ||
--- | ||
|
||
Fix ExecutorSchema isNonNullType method | ||
|
||
Client documents may wrap input types with non-nullable wrapper types not present in the schema. The ExecutorSchema should recognize these non-nullable types as such. |
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,90 @@ | ||
import { expect } from 'chai'; | ||
import { describe, it } from 'mocha'; | ||
|
||
import type { GraphQLNonNull, NamedTypeNode, NonNullTypeNode } from 'graphql'; | ||
import { | ||
GraphQLInputObjectType, | ||
GraphQLObjectType, | ||
GraphQLSchema, | ||
GraphQLString, | ||
Kind, | ||
} from 'graphql'; | ||
|
||
import { toExecutorSchema } from '..'; | ||
|
||
describe('ExecutorSchema:', () => { | ||
const input = new GraphQLInputObjectType({ | ||
name: 'Input', | ||
fields: { | ||
inputField: { | ||
type: GraphQLString, | ||
}, | ||
}, | ||
}); | ||
const query = new GraphQLObjectType({ | ||
name: 'Query', | ||
fields: { | ||
field: { | ||
type: GraphQLString, | ||
args: { | ||
arg: { | ||
type: input, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
const schema = new GraphQLSchema({ | ||
query, | ||
}); | ||
|
||
it('does not throw', () => { | ||
expect(() => toExecutorSchema(schema)).not.to.throw(); | ||
}); | ||
|
||
it('allows retrieving output types', () => { | ||
const executorSchema = toExecutorSchema(schema); | ||
const namedTypeNode: NamedTypeNode = { | ||
kind: Kind.NAMED_TYPE, | ||
name: { | ||
kind: Kind.NAME, | ||
value: 'Query', | ||
}, | ||
}; | ||
const type = executorSchema.getType(namedTypeNode); | ||
expect(type).to.equal(query); | ||
}); | ||
|
||
it('allows retrieving input types', () => { | ||
const executorSchema = toExecutorSchema(schema); | ||
const namedTypeNode: NamedTypeNode = { | ||
kind: Kind.NAMED_TYPE, | ||
name: { | ||
kind: Kind.NAME, | ||
value: 'Input', | ||
}, | ||
}; | ||
const type = executorSchema.getType(namedTypeNode); | ||
expect(type).to.equal(input); | ||
expect(executorSchema.isInputType(type)).to.equal(true); | ||
}); | ||
|
||
it('allows retrieving input types defined in schema wrapped with non-null', () => { | ||
const executorSchema = toExecutorSchema(schema); | ||
const nonNullTypeNode: NonNullTypeNode = { | ||
kind: Kind.NON_NULL_TYPE, | ||
type: { | ||
kind: Kind.NAMED_TYPE, | ||
name: { | ||
kind: Kind.NAME, | ||
value: 'Input', | ||
}, | ||
}, | ||
}; | ||
const type = executorSchema.getType(nonNullTypeNode); | ||
expect(type).to.not.equal(undefined); | ||
expect(executorSchema.isNonNullType(type)).to.equal(true); | ||
expect(executorSchema.isInputType(type)).to.equal(true); | ||
expect((type as GraphQLNonNull<any>).ofType).to.equal(input); | ||
}); | ||
}); |
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