@apollo/federation-internals
Advanced tools
Comparing version 2.0.0-alpha.3 to 2.0.0-alpha.4
@@ -232,7 +232,7 @@ "use strict"; | ||
switch (typeNode.kind) { | ||
case 'ListType': | ||
case graphql_1.Kind.LIST_TYPE: | ||
return new definitions_1.ListType(buildTypeReferenceFromAST(typeNode.type, schema)); | ||
case 'NonNullType': | ||
case graphql_1.Kind.NON_NULL_TYPE: | ||
const wrapped = buildTypeReferenceFromAST(typeNode.type, schema); | ||
if (wrapped.kind == 'NonNullType') { | ||
if (wrapped.kind == graphql_1.Kind.NON_NULL_TYPE) { | ||
throw new graphql_1.GraphQLError(`Cannot apply the non-null operator (!) twice to the same type`, typeNode); | ||
@@ -239,0 +239,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { ArgumentNode, ASTNode, DirectiveLocationEnum, DirectiveNode, DocumentNode, GraphQLError, GraphQLSchema, TypeNode, VariableDefinitionNode, VariableNode } from "graphql"; | ||
import { ConstArgumentNode, ASTNode, DirectiveLocation, ConstDirectiveNode, DocumentNode, GraphQLError, GraphQLSchema, TypeNode, VariableDefinitionNode, VariableNode } from "graphql"; | ||
import { CoreSpecDefinition, FeatureUrl } from "./coreSpec"; | ||
@@ -57,3 +57,3 @@ import { MapWithCachedArrays } from "./utils"; | ||
export declare function runtimeTypesIntersects(t1: CompositeType, t2: CompositeType): boolean; | ||
export declare const executableDirectiveLocations: DirectiveLocationEnum[]; | ||
export declare const executableDirectiveLocations: DirectiveLocation[]; | ||
export declare function typeToAST(type: Type): TypeNode; | ||
@@ -84,3 +84,3 @@ export declare function typeFromAST(schema: Schema, node: TypeNode): Type; | ||
}>(defOrDirective: Directive<T, TApplicationArgs> | DirectiveDefinition<TApplicationArgs>, args?: TApplicationArgs): Directive<T, TApplicationArgs>; | ||
appliedDirectivesToDirectiveNodes(): DirectiveNode[] | undefined; | ||
appliedDirectivesToDirectiveNodes(): ConstDirectiveNode[] | undefined; | ||
appliedDirectivesToString(): string; | ||
@@ -512,7 +512,7 @@ variablesInAppliedDirectives(): Variables; | ||
private removeArgumentInternal; | ||
get locations(): readonly DirectiveLocationEnum[]; | ||
addLocations(...locations: DirectiveLocationEnum[]): DirectiveDefinition; | ||
get locations(): readonly DirectiveLocation[]; | ||
addLocations(...locations: DirectiveLocation[]): DirectiveDefinition; | ||
addAllLocations(): DirectiveDefinition; | ||
addAllTypeLocations(): DirectiveDefinition; | ||
removeLocations(...locations: DirectiveLocationEnum[]): DirectiveDefinition; | ||
removeLocations(...locations: DirectiveLocation[]): DirectiveDefinition; | ||
applications(): readonly Directive<SchemaElement<any, any>, TApplicationArgs>[]; | ||
@@ -545,3 +545,3 @@ private addReferencer; | ||
setOfExtension(extension: Extension<any> | undefined): void; | ||
argumentsToAST(): ArgumentNode[] | undefined; | ||
argumentsToAST(): ConstArgumentNode[] | undefined; | ||
remove(): boolean; | ||
@@ -548,0 +548,0 @@ private removeInternal; |
@@ -213,12 +213,12 @@ "use strict"; | ||
const keyDirective = this.addBuiltInDirective(schema, exports.keyDirectiveName) | ||
.addLocations('OBJECT', 'INTERFACE'); | ||
.addLocations(graphql_1.DirectiveLocation.OBJECT, graphql_1.DirectiveLocation.INTERFACE); | ||
keyDirective.repeatable = true; | ||
keyDirective.addArgument('fields', fieldSetType); | ||
this.addBuiltInDirective(schema, exports.extendsDirectiveName) | ||
.addLocations('OBJECT', 'INTERFACE'); | ||
.addLocations(graphql_1.DirectiveLocation.OBJECT, graphql_1.DirectiveLocation.INTERFACE); | ||
this.addBuiltInDirective(schema, exports.externalDirectiveName) | ||
.addLocations('OBJECT', 'FIELD_DEFINITION'); | ||
.addLocations(graphql_1.DirectiveLocation.OBJECT, graphql_1.DirectiveLocation.FIELD_DEFINITION); | ||
for (const name of [exports.requiresDirectiveName, exports.providesDirectiveName]) { | ||
this.addBuiltInDirective(schema, name) | ||
.addLocations('FIELD_DEFINITION') | ||
.addLocations(graphql_1.DirectiveLocation.FIELD_DEFINITION) | ||
.addArgument('fields', fieldSetType); | ||
@@ -357,3 +357,3 @@ } | ||
return { | ||
kind: 'Document', | ||
kind: graphql_1.Kind.DOCUMENT, | ||
loc: document.loc, | ||
@@ -360,0 +360,0 @@ definitions |
@@ -13,3 +13,3 @@ "use strict"; | ||
addElementsToSchema(schema) { | ||
this.addDirective(schema, 'inaccessible').addLocations('FIELD_DEFINITION', 'OBJECT', 'INTERFACE', 'UNION'); | ||
this.addDirective(schema, 'inaccessible').addLocations(graphql_1.DirectiveLocation.FIELD_DEFINITION, graphql_1.DirectiveLocation.OBJECT, graphql_1.DirectiveLocation.INTERFACE, graphql_1.DirectiveLocation.UNION); | ||
} | ||
@@ -16,0 +16,0 @@ inaccessibleDirective(schema) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.JOIN_VERSIONS = exports.JoinSpecDefinition = exports.joinIdentity = void 0; | ||
const graphql_1 = require("graphql"); | ||
const coreSpec_1 = require("./coreSpec"); | ||
@@ -27,3 +28,3 @@ const definitions_1 = require("./definitions"); | ||
addElementsToSchema(schema) { | ||
const joinGraph = this.addDirective(schema, 'graph').addLocations("ENUM_VALUE"); | ||
const joinGraph = this.addDirective(schema, 'graph').addLocations(graphql_1.DirectiveLocation.ENUM_VALUE); | ||
joinGraph.addArgument('name', new definitions_1.NonNullType(schema.stringType())); | ||
@@ -33,3 +34,3 @@ joinGraph.addArgument('url', new definitions_1.NonNullType(schema.stringType())); | ||
const joinFieldSet = this.addScalarType(schema, 'FieldSet'); | ||
const joinType = this.addDirective(schema, 'type').addLocations("OBJECT", "INTERFACE", "UNION", "ENUM", "INPUT_OBJECT", "SCALAR"); | ||
const joinType = this.addDirective(schema, 'type').addLocations(graphql_1.DirectiveLocation.OBJECT, graphql_1.DirectiveLocation.INTERFACE, graphql_1.DirectiveLocation.UNION, graphql_1.DirectiveLocation.ENUM, graphql_1.DirectiveLocation.INPUT_OBJECT, graphql_1.DirectiveLocation.SCALAR); | ||
if (!this.isV01()) { | ||
@@ -43,3 +44,3 @@ joinType.repeatable = true; | ||
} | ||
const joinField = this.addDirective(schema, 'field').addLocations("FIELD_DEFINITION", "INPUT_FIELD_DEFINITION"); | ||
const joinField = this.addDirective(schema, 'field').addLocations(graphql_1.DirectiveLocation.FIELD_DEFINITION, graphql_1.DirectiveLocation.INPUT_FIELD_DEFINITION); | ||
joinField.repeatable = true; | ||
@@ -54,3 +55,3 @@ joinField.addArgument('graph', new definitions_1.NonNullType(graphEnum)); | ||
if (!this.isV01()) { | ||
const joinImplements = this.addDirective(schema, 'implements').addLocations("OBJECT", "INTERFACE"); | ||
const joinImplements = this.addDirective(schema, 'implements').addLocations(graphql_1.DirectiveLocation.OBJECT, graphql_1.DirectiveLocation.INTERFACE); | ||
joinImplements.repeatable = true; | ||
@@ -61,3 +62,3 @@ joinImplements.addArgument('graph', new definitions_1.NonNullType(graphEnum)); | ||
if (this.isV01()) { | ||
const joinOwner = this.addDirective(schema, 'owner').addLocations("OBJECT"); | ||
const joinOwner = this.addDirective(schema, 'owner').addLocations(graphql_1.DirectiveLocation.OBJECT); | ||
joinOwner.addArgument('graph', new definitions_1.NonNullType(graphEnum)); | ||
@@ -64,0 +65,0 @@ } |
@@ -273,11 +273,11 @@ "use strict"; | ||
return { | ||
kind: 'FragmentDefinition', | ||
kind: graphql_1.Kind.FRAGMENT_DEFINITION, | ||
name: { | ||
kind: 'Name', | ||
kind: graphql_1.Kind.NAME, | ||
value: this.name | ||
}, | ||
typeCondition: { | ||
kind: 'NamedType', | ||
kind: graphql_1.Kind.NAMED_TYPE, | ||
name: { | ||
kind: 'Name', | ||
kind: graphql_1.Kind.NAME, | ||
value: this.typeCondition.name | ||
@@ -494,3 +494,3 @@ } | ||
switch (node.kind) { | ||
case 'Field': | ||
case graphql_1.Kind.FIELD: | ||
const definition = fieldAccessor(this.parentType, node.name.value); | ||
@@ -505,3 +505,3 @@ validate(definition, () => `Cannot query field "${node.name.value}" on type "${this.parentType}".`, this.parentType.sourceAST); | ||
break; | ||
case 'InlineFragment': | ||
case graphql_1.Kind.INLINE_FRAGMENT: | ||
const element = new FragmentElement(this.parentType, (_b = node.typeCondition) === null || _b === void 0 ? void 0 : _b.name.value); | ||
@@ -511,3 +511,3 @@ selection = new InlineFragmentSelection(element, new SelectionSet(element.typeCondition ? element.typeCondition : element.parentType, this.fragments)); | ||
break; | ||
case 'FragmentSpread': | ||
case graphql_1.Kind.FRAGMENT_SPREAD: | ||
const fragmentName = node.name.value; | ||
@@ -568,3 +568,3 @@ validate(this.fragments, () => `Cannot find fragment name "${fragmentName}" (no fragments were provided)`); | ||
selections: [{ | ||
kind: 'Field', | ||
kind: graphql_1.Kind.FIELD, | ||
name: { | ||
@@ -701,3 +701,3 @@ kind: graphql_1.Kind.NAME, | ||
return { | ||
kind: 'Argument', | ||
kind: graphql_1.Kind.ARGUMENT, | ||
name: { kind: graphql_1.Kind.NAME, value: n }, | ||
@@ -721,3 +721,3 @@ value: (0, values_1.valueToAST)(v, this.field.definition.argument(n).type), | ||
return { | ||
kind: 'Field', | ||
kind: graphql_1.Kind.FIELD, | ||
name: { | ||
@@ -900,3 +900,3 @@ kind: graphql_1.Kind.NAME, | ||
return { | ||
kind: 'Directive', | ||
kind: graphql_1.Kind.DIRECTIVE, | ||
name: { | ||
@@ -910,4 +910,4 @@ kind: graphql_1.Kind.NAME, | ||
return { | ||
kind: 'FragmentSpread', | ||
name: { kind: 'Name', value: this.namedFragment.name }, | ||
kind: graphql_1.Kind.FRAGMENT_SPREAD, | ||
name: { kind: graphql_1.Kind.NAME, value: this.namedFragment.name }, | ||
directives: directiveNodes, | ||
@@ -1012,3 +1012,3 @@ }; | ||
const def = parsed.definitions[0]; | ||
validate(def.kind === 'OperationDefinition', () => 'Expected an operation definition but got a ' + def.kind); | ||
validate(def.kind === graphql_1.Kind.OPERATION_DEFINITION, () => 'Expected an operation definition but got a ' + def.kind); | ||
return def; | ||
@@ -1019,3 +1019,3 @@ } | ||
const operationAST = { | ||
kind: 'OperationDefinition', | ||
kind: graphql_1.Kind.OPERATION_DEFINITION, | ||
operation: operation.rootKind, | ||
@@ -1022,0 +1022,0 @@ selectionSet: operation.selectionSet.toSelectionSetNode(), |
@@ -1,6 +0,6 @@ | ||
import { DirectiveLocationEnum, GraphQLError } from "graphql"; | ||
import { DirectiveLocation, GraphQLError } from "graphql"; | ||
import { FeatureDefinition, FeatureDefinitions, FeatureVersion } from "./coreSpec"; | ||
import { DirectiveDefinition, Schema } from "./definitions"; | ||
export declare const tagIdentity = "https://specs.apollo.dev/tag"; | ||
export declare const tagLocations: DirectiveLocationEnum[]; | ||
export declare const tagLocations: DirectiveLocation[]; | ||
export declare class TagSpecDefinition extends FeatureDefinition { | ||
@@ -7,0 +7,0 @@ constructor(version: FeatureVersion); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.TAG_VERSIONS = exports.TagSpecDefinition = exports.tagLocations = exports.tagIdentity = void 0; | ||
const graphql_1 = require("graphql"); | ||
const coreSpec_1 = require("./coreSpec"); | ||
@@ -10,3 +11,8 @@ const definitions_1 = require("./definitions"); | ||
exports.tagIdentity = 'https://specs.apollo.dev/tag'; | ||
exports.tagLocations = ['FIELD_DEFINITION', 'OBJECT', 'INTERFACE', 'UNION']; | ||
exports.tagLocations = [ | ||
graphql_1.DirectiveLocation.FIELD_DEFINITION, | ||
graphql_1.DirectiveLocation.OBJECT, | ||
graphql_1.DirectiveLocation.INTERFACE, | ||
graphql_1.DirectiveLocation.UNION, | ||
]; | ||
const printedTagDefinition = 'directive @tag(name: String!) repeatable on FIELD_DEFINITION | INTERFACE | OBJECT | UNION'; | ||
@@ -13,0 +19,0 @@ class TagSpecDefinition extends coreSpec_1.FeatureDefinition { |
import { ArgumentDefinition, InputType, VariableDefinitions, Variables } from './definitions'; | ||
import { ArgumentNode, ValueNode } from 'graphql'; | ||
import { ArgumentNode, ValueNode, ConstValueNode } from 'graphql'; | ||
export declare function valueToString(v: any, expectedType?: InputType): string; | ||
@@ -11,2 +11,3 @@ export declare function valueEquals(a: any, b: any): boolean; | ||
export declare function withDefaultValues(value: any, argument: ArgumentDefinition<any>): any; | ||
export declare function valueNodeToConstValueNode(value: ValueNode): ConstValueNode; | ||
export declare function valueToAST(value: any, type: InputType): ValueNode | undefined; | ||
@@ -13,0 +14,0 @@ export declare function isValidValue(value: any, argument: ArgumentDefinition<any>, variableDefinitions: VariableDefinitions): boolean; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.variablesInValue = exports.argumentsFromAST = exports.valueFromAST = exports.isValidValue = exports.valueToAST = exports.withDefaultValues = exports.argumentsEquals = exports.valueEquals = exports.valueToString = void 0; | ||
exports.variablesInValue = exports.argumentsFromAST = exports.valueFromAST = exports.isValidValue = exports.valueToAST = exports.valueNodeToConstValueNode = exports.withDefaultValues = exports.argumentsEquals = exports.valueEquals = exports.valueToString = void 0; | ||
const definitions_1 = require("./definitions"); | ||
@@ -180,2 +180,28 @@ const graphql_1 = require("graphql"); | ||
const integerStringRegExp = /^-?(?:0|[1-9][0-9]*)$/; | ||
function objectFieldNodeToConst(field) { | ||
return { ...field, value: valueNodeToConstValueNode(field.value) }; | ||
} | ||
function valueNodeToConstValueNode(value) { | ||
if (value.kind === graphql_1.Kind.NULL | ||
|| value.kind === graphql_1.Kind.INT | ||
|| value.kind === graphql_1.Kind.FLOAT | ||
|| value.kind === graphql_1.Kind.STRING | ||
|| value.kind === graphql_1.Kind.BOOLEAN | ||
|| value.kind === graphql_1.Kind.ENUM) { | ||
return value; | ||
} | ||
if (value.kind === graphql_1.Kind.LIST) { | ||
const constValues = value.values.map(v => valueNodeToConstValueNode(v)); | ||
return { ...value, values: constValues }; | ||
} | ||
if (value.kind === graphql_1.Kind.OBJECT) { | ||
const constFields = value.fields.map(f => objectFieldNodeToConst(f)); | ||
return { ...value, fields: constFields }; | ||
} | ||
if (value.kind === graphql_1.Kind.VARIABLE) { | ||
throw new Error('Unexpected VariableNode in const AST'); | ||
} | ||
(0, utils_1.assertUnreachable)(value); | ||
} | ||
exports.valueNodeToConstValueNode = valueNodeToConstValueNode; | ||
function valueToAST(value, type) { | ||
@@ -182,0 +208,0 @@ if (value === undefined) { |
{ | ||
"name": "@apollo/federation-internals", | ||
"version": "2.0.0-alpha.3", | ||
"version": "2.0.0-alpha.4", | ||
"description": "Apollo Federation internal utilities", | ||
@@ -34,3 +34,3 @@ "main": "dist/index.js", | ||
"peerDependencies": { | ||
"graphql": "^15.7.0" | ||
"graphql": "^15.7.0 || ^16.0.0" | ||
}, | ||
@@ -40,3 +40,3 @@ "devDependencies": { | ||
}, | ||
"gitHead": "a8e0485664fafc7d9e3537f77c8907832f48d25b" | ||
"gitHead": "c32794a48598bac2e2372c23a2ea74ae187cce85" | ||
} |
@@ -18,3 +18,3 @@ import { DocumentNode } from 'graphql'; | ||
} | ||
return causes.map((err) => [err.extensions.code, err.message]); | ||
return causes.map((err) => [err.extensions.code as string, err.message]); | ||
} | ||
@@ -21,0 +21,0 @@ } |
import { | ||
DefinitionNode, | ||
DirectiveDefinitionNode, | ||
DirectiveLocationEnum, | ||
DirectiveLocation, | ||
DirectiveNode, | ||
@@ -21,3 +21,4 @@ DocumentNode, | ||
SchemaExtensionNode, | ||
parseType | ||
parseType, | ||
Kind, | ||
} from "graphql"; | ||
@@ -336,7 +337,7 @@ import { Maybe } from "graphql/jsutils/Maybe"; | ||
switch (typeNode.kind) { | ||
case 'ListType': | ||
case Kind.LIST_TYPE: | ||
return new ListType(buildTypeReferenceFromAST(typeNode.type, schema)); | ||
case 'NonNullType': | ||
case Kind.NON_NULL_TYPE: | ||
const wrapped = buildTypeReferenceFromAST(typeNode.type, schema); | ||
if (wrapped.kind == 'NonNullType') { | ||
if (wrapped.kind == Kind.NON_NULL_TYPE) { | ||
throw new GraphQLError(`Cannot apply the non-null operator (!) twice to the same type`, typeNode); | ||
@@ -373,3 +374,3 @@ } | ||
directive.repeatable = directiveNode.repeatable; | ||
const locations = directiveNode.locations.map(({ value }) => value as DirectiveLocationEnum); | ||
const locations = directiveNode.locations.map(({ value }) => value as DirectiveLocation); | ||
directive.addLocations(...locations); | ||
@@ -376,0 +377,0 @@ directive.description = directiveNode.description?.value; |
@@ -32,3 +32,14 @@ import { | ||
import { specifiedSDLRules } from "graphql/validation/specifiedRules"; | ||
import { ASTNode, DocumentNode, GraphQLError, KnownTypeNamesRule, parse, PossibleTypeExtensionsRule, print as printAST, Source } from "graphql"; | ||
import { | ||
ASTNode, | ||
DocumentNode, | ||
GraphQLError, | ||
Kind, | ||
KnownTypeNamesRule, | ||
parse, | ||
PossibleTypeExtensionsRule, | ||
print as printAST, | ||
Source, | ||
DirectiveLocation, | ||
} from "graphql"; | ||
import { defaultPrintOptions, printDirectiveDefinition } from "./print"; | ||
@@ -322,3 +333,3 @@ import { KnownTypeNamesInFederationRule } from "./validation/KnownTypeNamesInFederationRule"; | ||
const keyDirective = this.addBuiltInDirective(schema, keyDirectiveName) | ||
.addLocations('OBJECT', 'INTERFACE'); | ||
.addLocations(DirectiveLocation.OBJECT, DirectiveLocation.INTERFACE); | ||
// TODO: I believe fed 1 does not mark key repeatable and relax validation to accept repeating non-repeatable directive. | ||
@@ -332,10 +343,10 @@ // Do we want to perpetuate this? (Obviously, this is for historical reason and some graphQL implementations still do | ||
this.addBuiltInDirective(schema, extendsDirectiveName) | ||
.addLocations('OBJECT', 'INTERFACE'); | ||
.addLocations(DirectiveLocation.OBJECT, DirectiveLocation.INTERFACE); | ||
this.addBuiltInDirective(schema, externalDirectiveName) | ||
.addLocations('OBJECT', 'FIELD_DEFINITION'); | ||
.addLocations(DirectiveLocation.OBJECT, DirectiveLocation.FIELD_DEFINITION); | ||
for (const name of [requiresDirectiveName, providesDirectiveName]) { | ||
this.addBuiltInDirective(schema, name) | ||
.addLocations('FIELD_DEFINITION') | ||
.addLocations(DirectiveLocation.FIELD_DEFINITION) | ||
.addArgument('fields', fieldSetType); | ||
@@ -549,3 +560,3 @@ } | ||
return { | ||
kind: 'Document', | ||
kind: Kind.DOCUMENT, | ||
loc: document.loc, | ||
@@ -552,0 +563,0 @@ definitions |
@@ -10,3 +10,3 @@ import { FeatureDefinition, FeatureDefinitions, FeatureUrl, FeatureVersion } from "./coreSpec"; | ||
} from "./definitions"; | ||
import { GraphQLError } from "graphql"; | ||
import { GraphQLError, DirectiveLocation } from "graphql"; | ||
@@ -21,3 +21,8 @@ export const inaccessibleIdentity = 'https://specs.apollo.dev/inaccessible'; | ||
addElementsToSchema(schema: Schema) { | ||
this.addDirective(schema, 'inaccessible').addLocations('FIELD_DEFINITION', 'OBJECT', 'INTERFACE', 'UNION'); | ||
this.addDirective(schema, 'inaccessible').addLocations( | ||
DirectiveLocation.FIELD_DEFINITION, | ||
DirectiveLocation.OBJECT, | ||
DirectiveLocation.INTERFACE, | ||
DirectiveLocation.UNION, | ||
); | ||
} | ||
@@ -24,0 +29,0 @@ |
@@ -0,1 +1,2 @@ | ||
import { DirectiveLocation } from 'graphql'; | ||
import { FeatureDefinition, FeatureDefinitions, FeatureUrl, FeatureVersion } from "./coreSpec"; | ||
@@ -41,3 +42,3 @@ import { | ||
addElementsToSchema(schema: Schema) { | ||
const joinGraph = this.addDirective(schema, 'graph').addLocations("ENUM_VALUE"); | ||
const joinGraph = this.addDirective(schema, 'graph').addLocations(DirectiveLocation.ENUM_VALUE); | ||
joinGraph.addArgument('name', new NonNullType(schema.stringType())); | ||
@@ -51,3 +52,8 @@ joinGraph.addArgument('url', new NonNullType(schema.stringType())); | ||
const joinType = this.addDirective(schema, 'type').addLocations( | ||
"OBJECT", "INTERFACE", "UNION", "ENUM", "INPUT_OBJECT", "SCALAR" | ||
DirectiveLocation.OBJECT, | ||
DirectiveLocation.INTERFACE, | ||
DirectiveLocation.UNION, | ||
DirectiveLocation.ENUM, | ||
DirectiveLocation.INPUT_OBJECT, | ||
DirectiveLocation.SCALAR, | ||
); | ||
@@ -63,3 +69,3 @@ if (!this.isV01()) { | ||
const joinField = this.addDirective(schema, 'field').addLocations("FIELD_DEFINITION", "INPUT_FIELD_DEFINITION"); | ||
const joinField = this.addDirective(schema, 'field').addLocations(DirectiveLocation.FIELD_DEFINITION, DirectiveLocation.INPUT_FIELD_DEFINITION); | ||
joinField.repeatable = true; | ||
@@ -76,3 +82,3 @@ joinField.addArgument('graph', new NonNullType(graphEnum)); | ||
const joinImplements = this.addDirective(schema, 'implements').addLocations( | ||
"OBJECT", "INTERFACE" | ||
DirectiveLocation.OBJECT, DirectiveLocation.INTERFACE, | ||
); | ||
@@ -85,3 +91,3 @@ joinImplements.repeatable = true; | ||
if (this.isV01()) { | ||
const joinOwner = this.addDirective(schema, 'owner').addLocations("OBJECT"); | ||
const joinOwner = this.addDirective(schema, 'owner').addLocations(DirectiveLocation.OBJECT); | ||
joinOwner.addArgument('graph', new NonNullType(graphEnum)); | ||
@@ -88,0 +94,0 @@ } |
@@ -16,3 +16,5 @@ import { | ||
SelectionNode, | ||
SelectionSetNode | ||
SelectionSetNode, | ||
OperationTypeNode, | ||
NameNode, | ||
} from "graphql"; | ||
@@ -406,11 +408,11 @@ import { | ||
return { | ||
kind: 'FragmentDefinition', | ||
kind: Kind.FRAGMENT_DEFINITION, | ||
name: { | ||
kind: 'Name', | ||
kind: Kind.NAME, | ||
value: this.name | ||
}, | ||
typeCondition: { | ||
kind: 'NamedType', | ||
kind: Kind.NAMED_TYPE, | ||
name: { | ||
kind: 'Name', | ||
kind: Kind.NAME, | ||
value: this.typeCondition.name | ||
@@ -677,3 +679,3 @@ } | ||
switch (node.kind) { | ||
case 'Field': | ||
case Kind.FIELD: | ||
const definition: FieldDefinition<any> | undefined = fieldAccessor(this.parentType, node.name.value); | ||
@@ -691,3 +693,3 @@ validate(definition, () => `Cannot query field "${node.name.value}" on type "${this.parentType}".`, this.parentType.sourceAST); | ||
break; | ||
case 'InlineFragment': | ||
case Kind.INLINE_FRAGMENT: | ||
const element = new FragmentElement(this.parentType, node.typeCondition?.name.value); | ||
@@ -700,3 +702,3 @@ selection = new InlineFragmentSelection( | ||
break; | ||
case 'FragmentSpread': | ||
case Kind.FRAGMENT_SPREAD: | ||
const fragmentName = node.name.value; | ||
@@ -775,3 +777,3 @@ validate(this.fragments, () => `Cannot find fragment name "${fragmentName}" (no fragments were provided)`); | ||
selections: [{ | ||
kind: 'Field', | ||
kind: Kind.FIELD, | ||
name: { | ||
@@ -947,3 +949,3 @@ kind: Kind.NAME, | ||
return { | ||
kind: 'Argument', | ||
kind: Kind.ARGUMENT, | ||
name: { kind: Kind.NAME, value: n }, | ||
@@ -972,5 +974,5 @@ value: valueToAST(v, this.field.definition.argument(n)!.type!)!, | ||
toSelectionNode(): FieldNode { | ||
const alias = this.field.alias ? { kind: Kind.NAME, value: this.field.alias, } : undefined; | ||
const alias: NameNode | undefined = this.field.alias ? { kind: Kind.NAME, value: this.field.alias, } : undefined; | ||
return { | ||
kind: 'Field', | ||
kind: Kind.FIELD, | ||
name: { | ||
@@ -1218,3 +1220,3 @@ kind: Kind.NAME, | ||
return { | ||
kind: 'Directive', | ||
kind: Kind.DIRECTIVE, | ||
name: { | ||
@@ -1228,4 +1230,4 @@ kind: Kind.NAME, | ||
return { | ||
kind: 'FragmentSpread', | ||
name: { kind: 'Name', value: this.namedFragment.name }, | ||
kind: Kind.FRAGMENT_SPREAD, | ||
name: { kind: Kind.NAME, value: this.namedFragment.name }, | ||
directives: directiveNodes, | ||
@@ -1361,3 +1363,3 @@ }; | ||
const def = parsed.definitions[0]; | ||
validate(def.kind === 'OperationDefinition', () => 'Expected an operation definition but got a ' + def.kind); | ||
validate(def.kind === Kind.OPERATION_DEFINITION, () => 'Expected an operation definition but got a ' + def.kind); | ||
return def; | ||
@@ -1368,4 +1370,4 @@ } | ||
const operationAST: OperationDefinitionNode = { | ||
kind: 'OperationDefinition', | ||
operation: operation.rootKind, | ||
kind: Kind.OPERATION_DEFINITION, | ||
operation: operation.rootKind as OperationTypeNode, | ||
selectionSet: operation.selectionSet.toSelectionSetNode(), | ||
@@ -1372,0 +1374,0 @@ variableDefinitions: operation.variableDefinitions.toVariableDefinitionNodes(), |
@@ -1,2 +0,2 @@ | ||
import { DirectiveLocationEnum, GraphQLError } from "graphql"; | ||
import { DirectiveLocation, GraphQLError } from "graphql"; | ||
import { FeatureDefinition, FeatureDefinitions, FeatureUrl, FeatureVersion } from "./coreSpec"; | ||
@@ -10,3 +10,8 @@ import { DirectiveDefinition, NonNullType, Schema } from "./definitions"; | ||
export const tagLocations: DirectiveLocationEnum[] = ['FIELD_DEFINITION', 'OBJECT', 'INTERFACE', 'UNION']; | ||
export const tagLocations = [ | ||
DirectiveLocation.FIELD_DEFINITION, | ||
DirectiveLocation.OBJECT, | ||
DirectiveLocation.INTERFACE, | ||
DirectiveLocation.UNION, | ||
]; | ||
@@ -13,0 +18,0 @@ const printedTagDefinition = 'directive @tag(name: String!) repeatable on FIELD_DEFINITION | INTERFACE | OBJECT | UNION'; |
@@ -20,9 +20,18 @@ import { | ||
VariableDefinitions, | ||
Variables | ||
Variables, | ||
} from './definitions'; | ||
import { ArgumentNode, GraphQLError, Kind, print, ValueNode } from 'graphql'; | ||
import { | ||
ArgumentNode, | ||
GraphQLError, | ||
Kind, | ||
print, | ||
ValueNode, | ||
ObjectFieldNode, | ||
ConstValueNode, | ||
ConstObjectFieldNode, | ||
} from 'graphql'; | ||
import { didYouMean, suggestionList } from './suggestions'; | ||
import { inspect } from 'util'; | ||
import { sameType } from './types'; | ||
import { assert } from './utils'; | ||
import { assert, assertUnreachable } from './utils'; | ||
@@ -223,2 +232,35 @@ // Per-GraphQL spec, max and value for an Int type. | ||
function objectFieldNodeToConst(field: ObjectFieldNode): ConstObjectFieldNode { | ||
return { ...field, value: valueNodeToConstValueNode(field.value) }; | ||
} | ||
/** | ||
* Transforms a ValueNode to a ConstValueNode. This should only be invoked when we know that the value node can be const | ||
* as it will result in an exception if it contains a VariableNode | ||
*/ | ||
export function valueNodeToConstValueNode(value: ValueNode): ConstValueNode { | ||
if (value.kind === Kind.NULL | ||
|| value.kind === Kind.INT | ||
|| value.kind === Kind.FLOAT | ||
|| value.kind === Kind.STRING | ||
|| value.kind === Kind.BOOLEAN | ||
|| value.kind === Kind.ENUM | ||
) { | ||
return value; | ||
} | ||
if (value.kind === Kind.LIST) { | ||
const constValues = value.values.map(v => valueNodeToConstValueNode(v)); | ||
return { ...value, values: constValues }; | ||
} | ||
if (value.kind === Kind.OBJECT) { | ||
const constFields = value.fields.map(f => objectFieldNodeToConst(f)); | ||
return { ...value, fields: constFields }; | ||
} | ||
if (value.kind === Kind.VARIABLE) { | ||
// VarableNode does not exist in ConstValueNode | ||
throw new Error('Unexpected VariableNode in const AST'); | ||
} | ||
assertUnreachable(value); | ||
} | ||
// Adapted from the `astFromValue` function in graphQL-js | ||
@@ -275,3 +317,3 @@ export function valueToAST(value: any, type: InputType): ValueNode | undefined { | ||
} | ||
const fieldNodes = []; | ||
const fieldNodes: ObjectFieldNode[] = []; | ||
for (const field of type.fields()) { | ||
@@ -354,3 +396,3 @@ if (!field.type) { | ||
if (typeof value === 'object') { | ||
const fieldNodes = []; | ||
const fieldNodes: ObjectFieldNode[] = []; | ||
for (const key of Object.keys(value)) { | ||
@@ -357,0 +399,0 @@ const fieldValue = valueToASTUntyped(value[key]); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1198625
19251