diff --git a/src/type/__tests__/predicate-test.js b/src/type/__tests__/predicate-test.js index 7e655a7bab0..2a5f885b623 100644 --- a/src/type/__tests__/predicate-test.js +++ b/src/type/__tests__/predicate-test.js @@ -573,77 +573,87 @@ describe('Type predicates', () => { }); describe('isRequiredArgument', () => { - it('returns true for required arguments', () => { - const requiredArg = { + function buildArg(config) { + return { name: 'someArg', - type: GraphQLNonNull(GraphQLString), + description: undefined, + defaultValue: undefined, + astNode: undefined, + ...config, }; + } + + it('returns true for required arguments', () => { + const requiredArg = buildArg({ + type: GraphQLNonNull(GraphQLString), + }); expect(isRequiredArgument(requiredArg)).to.equal(true); }); it('returns false for optional arguments', () => { - const optArg1 = { - name: 'someArg', + const optArg1 = buildArg({ type: GraphQLString, - }; + }); expect(isRequiredArgument(optArg1)).to.equal(false); - const optArg2 = { - name: 'someArg', + const optArg2 = buildArg({ type: GraphQLString, defaultValue: null, - }; + }); expect(isRequiredArgument(optArg2)).to.equal(false); - const optArg3 = { - name: 'someArg', + const optArg3 = buildArg({ type: GraphQLList(GraphQLNonNull(GraphQLString)), - }; + }); expect(isRequiredArgument(optArg3)).to.equal(false); - const optArg4 = { - name: 'someArg', + const optArg4 = buildArg({ type: GraphQLNonNull(GraphQLString), defaultValue: 'default', - }; + }); expect(isRequiredArgument(optArg4)).to.equal(false); }); }); describe('isRequiredInputField', () => { + function buildInputField(config) { + return { + name: 'someInputField', + description: undefined, + defaultValue: undefined, + astNode: undefined, + ...config, + }; + } + it('returns true for required input field', () => { - const requiredField = { - name: 'someField', + const requiredField = buildInputField({ type: GraphQLNonNull(GraphQLString), - }; + }); expect(isRequiredInputField(requiredField)).to.equal(true); }); it('returns false for optional input field', () => { - const optField1 = { - name: 'someField', + const optField1 = buildInputField({ type: GraphQLString, - }; + }); expect(isRequiredInputField(optField1)).to.equal(false); - const optField2 = { - name: 'someField', + const optField2 = buildInputField({ type: GraphQLString, defaultValue: null, - }; + }); expect(isRequiredInputField(optField2)).to.equal(false); - const optField3 = { - name: 'someField', + const optField3 = buildInputField({ type: GraphQLList(GraphQLNonNull(GraphQLString)), - }; + }); expect(isRequiredInputField(optField3)).to.equal(false); - const optField4 = { - name: 'someField', + const optField4 = buildInputField({ type: GraphQLNonNull(GraphQLString), defaultValue: 'default', - }; + }); expect(isRequiredInputField(optField4)).to.equal(false); }); }); diff --git a/src/type/definition.js b/src/type/definition.js index ce151b6d899..f2105c049f3 100644 --- a/src/type/definition.js +++ b/src/type/definition.js @@ -909,16 +909,16 @@ export type GraphQLField< resolve?: GraphQLFieldResolver, subscribe?: GraphQLFieldResolver, isDeprecated?: boolean, - deprecationReason?: ?string, - astNode?: ?FieldDefinitionNode, + deprecationReason: ?string, + astNode: ?FieldDefinitionNode, |}; export type GraphQLArgument = {| name: string, - description?: ?string, + description: ?string, type: GraphQLInputType, defaultValue?: mixed, - astNode?: ?InputValueDefinitionNode, + astNode: ?InputValueDefinitionNode, |}; export function isRequiredArgument(arg: GraphQLArgument): boolean %checks { @@ -1286,7 +1286,7 @@ export type GraphQLEnumValue /* */ = {| value: any /* T */, isDeprecated?: boolean, deprecationReason: ?string, - astNode?: ?EnumValueDefinitionNode, + astNode: ?EnumValueDefinitionNode, |}; /** @@ -1407,10 +1407,10 @@ export type GraphQLInputFieldConfigMap = ObjMap; export type GraphQLInputField = {| name: string, - description?: ?string, + description: ?string, type: GraphQLInputType, defaultValue?: mixed, - astNode?: ?InputValueDefinitionNode, + astNode: ?InputValueDefinitionNode, |}; export function isRequiredInputField( diff --git a/src/type/introspection.js b/src/type/introspection.js index eff1e0c42e3..3f85aad6a90 100644 --- a/src/type/introspection.js +++ b/src/type/introspection.js @@ -438,14 +438,25 @@ export const SchemaMetaFieldDef: GraphQLField = { description: 'Access the current type schema of this server.', args: [], resolve: (source, args, context, { schema }) => schema, + deprecationReason: undefined, + astNode: undefined, }; export const TypeMetaFieldDef: GraphQLField = { name: '__type', type: __Type, description: 'Request the type information of a single type.', - args: [{ name: 'name', type: GraphQLNonNull(GraphQLString) }], + args: [ + { + name: 'name', + description: undefined, + type: GraphQLNonNull(GraphQLString), + astNode: undefined, + }, + ], resolve: (source, { name }, context, { schema }) => schema.getType(name), + deprecationReason: undefined, + astNode: undefined, }; export const TypeNameMetaFieldDef: GraphQLField = { @@ -454,6 +465,8 @@ export const TypeNameMetaFieldDef: GraphQLField = { description: 'The name of the current Object type at runtime.', args: [], resolve: (source, args, context, { parentType }) => parentType.name, + deprecationReason: undefined, + astNode: undefined, }; export const introspectionTypes = Object.freeze([