Skip to content

Commit f498b7b

Browse files
committed
definitions: make constructed fields non-optional
Reflects changes in #2089
1 parent 7782190 commit f498b7b

File tree

3 files changed

+65
-41
lines changed

3 files changed

+65
-41
lines changed

src/type/__tests__/predicate-test.js

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -573,77 +573,87 @@ describe('Type predicates', () => {
573573
});
574574

575575
describe('isRequiredArgument', () => {
576-
it('returns true for required arguments', () => {
577-
const requiredArg = {
576+
function buildArg(config) {
577+
return {
578578
name: 'someArg',
579-
type: GraphQLNonNull(GraphQLString),
579+
description: undefined,
580+
defaultValue: undefined,
581+
astNode: undefined,
582+
...config,
580583
};
584+
}
585+
586+
it('returns true for required arguments', () => {
587+
const requiredArg = buildArg({
588+
type: GraphQLNonNull(GraphQLString),
589+
});
581590
expect(isRequiredArgument(requiredArg)).to.equal(true);
582591
});
583592

584593
it('returns false for optional arguments', () => {
585-
const optArg1 = {
586-
name: 'someArg',
594+
const optArg1 = buildArg({
587595
type: GraphQLString,
588-
};
596+
});
589597
expect(isRequiredArgument(optArg1)).to.equal(false);
590598

591-
const optArg2 = {
592-
name: 'someArg',
599+
const optArg2 = buildArg({
593600
type: GraphQLString,
594601
defaultValue: null,
595-
};
602+
});
596603
expect(isRequiredArgument(optArg2)).to.equal(false);
597604

598-
const optArg3 = {
599-
name: 'someArg',
605+
const optArg3 = buildArg({
600606
type: GraphQLList(GraphQLNonNull(GraphQLString)),
601-
};
607+
});
602608
expect(isRequiredArgument(optArg3)).to.equal(false);
603609

604-
const optArg4 = {
605-
name: 'someArg',
610+
const optArg4 = buildArg({
606611
type: GraphQLNonNull(GraphQLString),
607612
defaultValue: 'default',
608-
};
613+
});
609614
expect(isRequiredArgument(optArg4)).to.equal(false);
610615
});
611616
});
612617

613618
describe('isRequiredInputField', () => {
619+
function buildInputField(config) {
620+
return {
621+
name: 'someInputField',
622+
description: undefined,
623+
defaultValue: undefined,
624+
astNode: undefined,
625+
...config,
626+
};
627+
}
628+
614629
it('returns true for required input field', () => {
615-
const requiredField = {
616-
name: 'someField',
630+
const requiredField = buildInputField({
617631
type: GraphQLNonNull(GraphQLString),
618-
};
632+
});
619633
expect(isRequiredInputField(requiredField)).to.equal(true);
620634
});
621635

622636
it('returns false for optional input field', () => {
623-
const optField1 = {
624-
name: 'someField',
637+
const optField1 = buildInputField({
625638
type: GraphQLString,
626-
};
639+
});
627640
expect(isRequiredInputField(optField1)).to.equal(false);
628641

629-
const optField2 = {
630-
name: 'someField',
642+
const optField2 = buildInputField({
631643
type: GraphQLString,
632644
defaultValue: null,
633-
};
645+
});
634646
expect(isRequiredInputField(optField2)).to.equal(false);
635647

636-
const optField3 = {
637-
name: 'someField',
648+
const optField3 = buildInputField({
638649
type: GraphQLList(GraphQLNonNull(GraphQLString)),
639-
};
650+
});
640651
expect(isRequiredInputField(optField3)).to.equal(false);
641652

642-
const optField4 = {
643-
name: 'someField',
653+
const optField4 = buildInputField({
644654
type: GraphQLNonNull(GraphQLString),
645655
defaultValue: 'default',
646-
};
656+
});
647657
expect(isRequiredInputField(optField4)).to.equal(false);
648658
});
649659
});

src/type/definition.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -909,16 +909,16 @@ export type GraphQLField<
909909
resolve?: GraphQLFieldResolver<TSource, TContext, TArgs>,
910910
subscribe?: GraphQLFieldResolver<TSource, TContext, TArgs>,
911911
isDeprecated?: boolean,
912-
deprecationReason?: ?string,
913-
astNode?: ?FieldDefinitionNode,
912+
deprecationReason: ?string,
913+
astNode: ?FieldDefinitionNode,
914914
|};
915915

916916
export type GraphQLArgument = {|
917917
name: string,
918-
description?: ?string,
918+
description: ?string,
919919
type: GraphQLInputType,
920-
defaultValue?: mixed,
921-
astNode?: ?InputValueDefinitionNode,
920+
defaultValue: mixed,
921+
astNode: ?InputValueDefinitionNode,
922922
|};
923923

924924
export function isRequiredArgument(arg: GraphQLArgument): boolean %checks {
@@ -1284,9 +1284,9 @@ export type GraphQLEnumValue /* <T> */ = {|
12841284
name: string,
12851285
description: ?string,
12861286
value: any /* T */,
1287-
isDeprecated?: boolean,
1287+
isDeprecated: boolean,
12881288
deprecationReason: ?string,
1289-
astNode?: ?EnumValueDefinitionNode,
1289+
astNode: ?EnumValueDefinitionNode,
12901290
|};
12911291

12921292
/**
@@ -1407,10 +1407,10 @@ export type GraphQLInputFieldConfigMap = ObjMap<GraphQLInputFieldConfig>;
14071407

14081408
export type GraphQLInputField = {|
14091409
name: string,
1410-
description?: ?string,
1410+
description: ?string,
14111411
type: GraphQLInputType,
1412-
defaultValue?: mixed,
1413-
astNode?: ?InputValueDefinitionNode,
1412+
defaultValue: mixed,
1413+
astNode: ?InputValueDefinitionNode,
14141414
|};
14151415

14161416
export function isRequiredInputField(

src/type/introspection.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,14 +438,26 @@ export const SchemaMetaFieldDef: GraphQLField<mixed, mixed> = {
438438
description: 'Access the current type schema of this server.',
439439
args: [],
440440
resolve: (source, args, context, { schema }) => schema,
441+
deprecationReason: undefined,
442+
astNode: undefined,
441443
};
442444

443445
export const TypeMetaFieldDef: GraphQLField<mixed, mixed> = {
444446
name: '__type',
445447
type: __Type,
446448
description: 'Request the type information of a single type.',
447-
args: [{ name: 'name', type: GraphQLNonNull(GraphQLString) }],
449+
args: [
450+
{
451+
name: 'name',
452+
description: undefined,
453+
type: GraphQLNonNull(GraphQLString),
454+
defaultValue: undefined,
455+
astNode: undefined,
456+
},
457+
],
448458
resolve: (source, { name }, context, { schema }) => schema.getType(name),
459+
deprecationReason: undefined,
460+
astNode: undefined,
449461
};
450462

451463
export const TypeNameMetaFieldDef: GraphQLField<mixed, mixed> = {
@@ -454,6 +466,8 @@ export const TypeNameMetaFieldDef: GraphQLField<mixed, mixed> = {
454466
description: 'The name of the current Object type at runtime.',
455467
args: [],
456468
resolve: (source, args, context, { parentType }) => parentType.name,
469+
deprecationReason: undefined,
470+
astNode: undefined,
457471
};
458472

459473
export const introspectionTypes = Object.freeze([

0 commit comments

Comments
 (0)