Skip to content

Commit

Permalink
do not destructure Kind from graphql (#3085)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaMachina authored Mar 19, 2023
1 parent 4a2284f commit 283d979
Showing 1 changed file with 22 additions and 40 deletions.
62 changes: 22 additions & 40 deletions packages/graphql-language-service-server/src/GraphQLCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,6 @@ import { Logger } from './Logger';
// Maximum files to read when processing GraphQL files.
const MAX_READS = 200;

const {
DOCUMENT,
FRAGMENT_DEFINITION,
OBJECT_TYPE_DEFINITION,
INTERFACE_TYPE_DEFINITION,
ENUM_TYPE_DEFINITION,
UNION_TYPE_DEFINITION,
SCALAR_TYPE_DEFINITION,
INPUT_OBJECT_TYPE_DEFINITION,
SCALAR_TYPE_EXTENSION,
OBJECT_TYPE_EXTENSION,
INTERFACE_TYPE_EXTENSION,
UNION_TYPE_EXTENSION,
ENUM_TYPE_EXTENSION,
INPUT_OBJECT_TYPE_EXTENSION,
DIRECTIVE_DEFINITION,
} = Kind;

export async function getGraphQLCache({
parser,
logger,
Expand Down Expand Up @@ -440,7 +422,7 @@ export class GraphQLCache implements GraphQLCacheInterface {
return;
}
ast.definitions.forEach(definition => {
if (definition.kind === FRAGMENT_DEFINITION) {
if (definition.kind === Kind.FRAGMENT_DEFINITION) {
cache.set(definition.name.value, {
filePath,
content: query,
Expand Down Expand Up @@ -503,9 +485,9 @@ export class GraphQLCache implements GraphQLCacheInterface {
}
ast.definitions.forEach(definition => {
if (
definition.kind === OBJECT_TYPE_DEFINITION ||
definition.kind === INPUT_OBJECT_TYPE_DEFINITION ||
definition.kind === ENUM_TYPE_DEFINITION
definition.kind === Kind.OBJECT_TYPE_DEFINITION ||
definition.kind === Kind.INPUT_OBJECT_TYPE_DEFINITION ||
definition.kind === Kind.ENUM_TYPE_DEFINITION
) {
cache.set(definition.name.value, {
filePath,
Expand Down Expand Up @@ -562,19 +544,19 @@ export class GraphQLCache implements GraphQLCacheInterface {
}
ast.definitions.forEach(definition => {
switch (definition.kind) {
case OBJECT_TYPE_DEFINITION:
case INTERFACE_TYPE_DEFINITION:
case ENUM_TYPE_DEFINITION:
case UNION_TYPE_DEFINITION:
case SCALAR_TYPE_DEFINITION:
case INPUT_OBJECT_TYPE_DEFINITION:
case SCALAR_TYPE_EXTENSION:
case OBJECT_TYPE_EXTENSION:
case INTERFACE_TYPE_EXTENSION:
case UNION_TYPE_EXTENSION:
case ENUM_TYPE_EXTENSION:
case INPUT_OBJECT_TYPE_EXTENSION:
case DIRECTIVE_DEFINITION:
case Kind.OBJECT_TYPE_DEFINITION:
case Kind.INTERFACE_TYPE_DEFINITION:
case Kind.ENUM_TYPE_DEFINITION:
case Kind.UNION_TYPE_DEFINITION:
case Kind.SCALAR_TYPE_DEFINITION:
case Kind.INPUT_OBJECT_TYPE_DEFINITION:
case Kind.SCALAR_TYPE_EXTENSION:
case Kind.OBJECT_TYPE_EXTENSION:
case Kind.INTERFACE_TYPE_EXTENSION:
case Kind.UNION_TYPE_EXTENSION:
case Kind.ENUM_TYPE_EXTENSION:
case Kind.INPUT_OBJECT_TYPE_EXTENSION:
case Kind.DIRECTIVE_DEFINITION:
typeExtensions.push(definition);
break;
}
Expand All @@ -601,7 +583,7 @@ export class GraphQLCache implements GraphQLCacheInterface {
}

return extendSchema(schema, {
kind: DOCUMENT,
kind: Kind.DOCUMENT,
definitions: typeExtensions,
});
}
Expand Down Expand Up @@ -747,17 +729,17 @@ export class GraphQLCache implements GraphQLCacheInterface {
if (asts) {
asts.forEach(ast => {
ast.definitions.forEach(definition => {
if (definition.kind === FRAGMENT_DEFINITION) {
if (definition.kind === Kind.FRAGMENT_DEFINITION) {
fragmentDefinitions.set(definition.name.value, {
filePath,
content,
definition,
});
}
if (
definition.kind === OBJECT_TYPE_DEFINITION ||
definition.kind === INPUT_OBJECT_TYPE_DEFINITION ||
definition.kind === ENUM_TYPE_DEFINITION
definition.kind === Kind.OBJECT_TYPE_DEFINITION ||
definition.kind === Kind.INPUT_OBJECT_TYPE_DEFINITION ||
definition.kind === Kind.ENUM_TYPE_DEFINITION
) {
objectTypeDefinitions.set(definition.name.value, {
filePath,
Expand Down

0 comments on commit 283d979

Please sign in to comment.