Skip to content

Commit

Permalink
Various fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Jul 2, 2020
1 parent 171aec5 commit 08374e7
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 40 deletions.
4 changes: 2 additions & 2 deletions src/type/__tests__/definition-test.js
Expand Up @@ -281,8 +281,8 @@ describe('Type System: Objects', () => {
description: undefined,
type: ScalarType,
defaultValue: undefined,
deprecationReason: undefined,
isDeprecated: false,
deprecationReason: undefined,
extensions: undefined,
astNode: undefined,
},
Expand Down Expand Up @@ -774,8 +774,8 @@ describe('Type System: Input Objects', () => {
description: undefined,
type: ScalarType,
defaultValue: undefined,
deprecationReason: undefined,
isDeprecated: false,
deprecationReason: undefined,
extensions: undefined,
astNode: undefined,
},
Expand Down
4 changes: 4 additions & 0 deletions src/type/__tests__/directive-test.js
Expand Up @@ -39,6 +39,8 @@ describe('Type System: Directive', () => {
description: undefined,
type: GraphQLString,
defaultValue: undefined,
isDeprecated: false,
deprecationReason: undefined,
extensions: undefined,
astNode: undefined,
},
Expand All @@ -47,6 +49,8 @@ describe('Type System: Directive', () => {
description: undefined,
type: GraphQLInt,
defaultValue: undefined,
isDeprecated: false,
deprecationReason: undefined,
extensions: undefined,
astNode: undefined,
},
Expand Down
2 changes: 1 addition & 1 deletion src/type/__tests__/introspection-test.js
Expand Up @@ -951,8 +951,8 @@ describe('Introspection', () => {
isRepeatable: false,
locations: [
'FIELD_DEFINITION',
'ENUM_VALUE',
'ARGUMENT_DEFINITION',
'ENUM_VALUE',
'INPUT_FIELD_DEFINITION',
],
args: [
Expand Down
4 changes: 4 additions & 0 deletions src/type/__tests__/predicate-test.js
Expand Up @@ -549,6 +549,8 @@ describe('Type predicates', () => {
name: 'someArg',
description: undefined,
defaultValue: undefined,
isDeprecated: false,
deprecationReason: null,
extensions: undefined,
astNode: undefined,
...config,
Expand Down Expand Up @@ -593,6 +595,8 @@ describe('Type predicates', () => {
name: 'someInputField',
description: undefined,
defaultValue: undefined,
isDeprecated: false,
deprecationReason: null,
extensions: undefined,
astNode: undefined,
...config,
Expand Down
6 changes: 5 additions & 1 deletion src/type/definition.d.ts
Expand Up @@ -546,7 +546,6 @@ export interface GraphQLArgumentConfig {
description?: Maybe<string>;
type: GraphQLInputType;
defaultValue?: any;
isDeprecated?: boolean;
deprecationReason?: Maybe<string>;
extensions?: Maybe<Readonly<GraphQLArgumentExtensions>>;
astNode?: Maybe<InputValueDefinitionNode>;
Expand Down Expand Up @@ -578,6 +577,8 @@ export interface GraphQLArgument {
description: Maybe<string>;
type: GraphQLInputType;
defaultValue: any;
isDeprecated: boolean;
deprecationReason: Maybe<string>;
extensions: Maybe<Readonly<GraphQLArgumentExtensions>>;
astNode: Maybe<InputValueDefinitionNode>;
}
Expand Down Expand Up @@ -917,6 +918,7 @@ export interface GraphQLInputFieldConfig {
description?: Maybe<string>;
type: GraphQLInputType;
defaultValue?: any;
deprecationReason?: Maybe<string>;
extensions?: Maybe<Readonly<GraphQLInputFieldExtensions>>;
astNode?: Maybe<InputValueDefinitionNode>;
}
Expand All @@ -930,6 +932,8 @@ export interface GraphQLInputField {
description?: Maybe<string>;
type: GraphQLInputType;
defaultValue?: any;
isDeprecated: boolean;
deprecationReason: Maybe<string>;
extensions: Maybe<Readonly<GraphQLInputFieldExtensions>>;
astNode?: Maybe<InputValueDefinitionNode>;
}
Expand Down
42 changes: 23 additions & 19 deletions src/type/definition.js
Expand Up @@ -848,16 +848,23 @@ function defineFieldMap<TSource, TContext>(
`${config.name}.${fieldName} args must be an object with argument names as keys.`,
);

const args = objectEntries(argsConfig).map(([argName, argConfig]) => ({
name: argName,
description: argConfig.description,
type: argConfig.type,
defaultValue: argConfig.defaultValue,
extensions: argConfig.extensions && toObjMap(argConfig.extensions),
isDeprecated: argConfig.deprecationReason != null,
deprecationReason: argConfig.deprecationReason,
astNode: argConfig.astNode,
}));
const args = objectEntries(argsConfig).map(([argName, argConfig]) => {
devAssert(
!('isDeprecated' in argConfig),
`${config.name}.${fieldName}.${argName} should provide "deprecationReason" instead of "isDeprecated".`,
);

return {
name: argName,
description: argConfig.description,
type: argConfig.type,
defaultValue: argConfig.defaultValue,
isDeprecated: argConfig.deprecationReason != null,
deprecationReason: argConfig.deprecationReason,
extensions: argConfig.extensions && toObjMap(argConfig.extensions),
astNode: argConfig.astNode,
};
});

return {
name: fieldName,
Expand Down Expand Up @@ -905,7 +912,6 @@ export function argsToArgsConfig(
type: arg.type,
defaultValue: arg.defaultValue,
deprecationReason: arg.deprecationReason,
isDeprecated: arg.deprecationReason != null,
extensions: arg.extensions,
astNode: arg.astNode,
}),
Expand Down Expand Up @@ -983,7 +989,6 @@ export type GraphQLArgumentConfig = {|
defaultValue?: mixed,
extensions?: ?ReadOnlyObjMapLike<mixed>,
deprecationReason?: ?string,
isDeprecated?: boolean,
astNode?: ?InputValueDefinitionNode,
|};

Expand Down Expand Up @@ -1013,8 +1018,8 @@ export type GraphQLArgument = {|
description: ?string,
type: GraphQLInputType,
defaultValue: mixed,
isDeprecated?: boolean,
deprecationReason?: ?string,
isDeprecated: boolean,
deprecationReason: ?string,
extensions: ?ReadOnlyObjMap<mixed>,
astNode: ?InputValueDefinitionNode,
|};
Expand Down Expand Up @@ -1582,17 +1587,16 @@ function defineInputFieldMap(
);
devAssert(
!('isDeprecated' in fieldConfig),
`${config.name}.${fieldName} should provide "deprecationReason" ` +
'instead of "isDeprecated".',
`${config.name}.${fieldName} should provide "deprecationReason" instead of "isDeprecated".`,
);

return {
name: fieldName,
description: fieldConfig.description,
type: fieldConfig.type,
defaultValue: fieldConfig.defaultValue,
deprecationReason: fieldConfig.deprecationReason,
isDeprecated: fieldConfig.deprecationReason != null,
deprecationReason: fieldConfig.deprecationReason,
extensions: fieldConfig.extensions && toObjMap(fieldConfig.extensions),
astNode: fieldConfig.astNode,
};
Expand Down Expand Up @@ -1624,8 +1628,8 @@ export type GraphQLInputField = {|
description: ?string,
type: GraphQLInputType,
defaultValue: mixed,
isDeprecated?: boolean,
deprecationReason?: ?string,
isDeprecated: boolean,
deprecationReason: ?string,
extensions: ?ReadOnlyObjMap<mixed>,
astNode: ?InputValueDefinitionNode,
|};
Expand Down
27 changes: 18 additions & 9 deletions src/type/directives.js
Expand Up @@ -75,14 +75,23 @@ export class GraphQLDirective {
`@${config.name} args must be an object with argument names as keys.`,
);

this.args = objectEntries(args).map(([argName, argConfig]) => ({
name: argName,
description: argConfig.description,
type: argConfig.type,
defaultValue: argConfig.defaultValue,
extensions: argConfig.extensions && toObjMap(argConfig.extensions),
astNode: argConfig.astNode,
}));
this.args = objectEntries(args).map(([argName, argConfig]) => {
devAssert(
!('isDeprecated' in argConfig),
`@${config.name}.${argName} should provide "deprecationReason" instead of "isDeprecated".`,
);

return {
name: argName,
description: argConfig.description,
type: argConfig.type,
defaultValue: argConfig.defaultValue,
isDeprecated: argConfig.deprecationReason != null,
deprecationReason: argConfig.deprecationReason,
extensions: argConfig.extensions && toObjMap(argConfig.extensions),
astNode: argConfig.astNode,
};
});
}

toConfig(): {|
Expand Down Expand Up @@ -182,8 +191,8 @@ export const GraphQLDeprecatedDirective = new GraphQLDirective({
description: 'Marks an element of a GraphQL schema as no longer supported.',
locations: [
DirectiveLocation.FIELD_DEFINITION,
DirectiveLocation.ENUM_VALUE,
DirectiveLocation.ARGUMENT_DEFINITION,
DirectiveLocation.ENUM_VALUE,
DirectiveLocation.INPUT_FIELD_DEFINITION,
],
args: {
Expand Down
2 changes: 2 additions & 0 deletions src/type/introspection.js
Expand Up @@ -512,6 +512,8 @@ export const TypeMetaFieldDef: GraphQLField<mixed, mixed> = {
description: undefined,
type: GraphQLNonNull(GraphQLString),
defaultValue: undefined,
isDeprecated: false,
deprecationReason: undefined,
extensions: undefined,
astNode: undefined,
},
Expand Down
4 changes: 2 additions & 2 deletions src/utilities/__tests__/printSchema-test.js
Expand Up @@ -629,7 +629,7 @@ describe('Type System Printer', () => {
Explains why this element was deprecated, usually also including a suggestion for how to access supported similar data. Formatted using the Markdown syntax, as specified by [CommonMark](https://commonmark.org/).
"""
reason: String = "No longer supported"
) on FIELD_DEFINITION | ENUM_VALUE | ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION
) on FIELD_DEFINITION | ARGUMENT_DEFINITION | ENUM_VALUE | INPUT_FIELD_DEFINITION
"""Exposes a URL that specifies the behaviour of this scalar."""
directive @specifiedBy(
Expand Down Expand Up @@ -852,7 +852,7 @@ describe('Type System Printer', () => {
directive @deprecated(
# Explains why this element was deprecated, usually also including a suggestion for how to access supported similar data. Formatted using the Markdown syntax, as specified by [CommonMark](https://commonmark.org/).
reason: String = "No longer supported"
) on FIELD_DEFINITION | ENUM_VALUE | ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION
) on FIELD_DEFINITION | ARGUMENT_DEFINITION | ENUM_VALUE | INPUT_FIELD_DEFINITION
# Exposes a URL that specifies the behaviour of this scalar.
directive @specifiedBy(
Expand Down
11 changes: 5 additions & 6 deletions src/utilities/printSchema.js
Expand Up @@ -232,7 +232,7 @@ function printEnum(type: GraphQLEnumType, options): string {
printDescription(options, value, ' ', !i) +
' ' +
value.name +
printDeprecated(value),
printDeprecated(value.deprecationReason),
);

return (
Expand All @@ -259,7 +259,7 @@ function printFields(options, type) {
printArgs(options, f.args, ' ') +
': ' +
String(f.type) +
printDeprecated(f),
printDeprecated(f.deprecationReason),
);
return printBlock(fields);
}
Expand Down Expand Up @@ -301,7 +301,7 @@ function printInputValue(arg) {
if (defaultAST) {
argDecl += ` = ${print(defaultAST)}`;
}
return argDecl + printDeprecated(arg);
return argDecl + printDeprecated(arg.deprecationReason);
}

function printDirective(directive, options) {
Expand All @@ -316,11 +316,10 @@ function printDirective(directive, options) {
);
}

function printDeprecated(fieldOrEnumVal) {
if (fieldOrEnumVal.deprecationReason == null) {
function printDeprecated(reason) {
if (reason == null) {
return '';
}
const reason = fieldOrEnumVal.deprecationReason;
const reasonAST = astFromValue(reason, GraphQLString);
if (reasonAST && reason !== DEFAULT_DEPRECATION_REASON) {
return ' @deprecated(reason: ' + print(reasonAST) + ')';
Expand Down

0 comments on commit 08374e7

Please sign in to comment.