gqlQuery.ts (hoppscotch-2.2.1) | : | gqlQuery.ts (hoppscotch-3.0.0) | ||
---|---|---|---|---|
import { Ref } from "@nuxtjs/composition-api" | import { Ref } from "vue" | |||
import { | import { | |||
GraphQLError, | GraphQLError, | |||
GraphQLSchema, | GraphQLSchema, | |||
parse as gqlParse, | parse as gqlParse, | |||
validate as gqlValidate, | validate as gqlValidate, | |||
} from "graphql" | } from "graphql" | |||
import { LinterDefinition, LinterResult } from "./linter" | import { LinterDefinition, LinterResult } from "./linter" | |||
/** | /** | |||
* Creates a Linter function that can lint a GQL query against a given | * Creates a Linter function that can lint a GQL query against a given | |||
skipping to change at line 27 | skipping to change at line 27 | |||
if (text === "") return Promise.resolve([]) | if (text === "") return Promise.resolve([]) | |||
if (!schema.value) return Promise.resolve([]) | if (!schema.value) return Promise.resolve([]) | |||
try { | try { | |||
const doc = gqlParse(text) | const doc = gqlParse(text) | |||
const results = gqlValidate(schema.value, doc).map( | const results = gqlValidate(schema.value, doc).map( | |||
({ locations, message }) => | ({ locations, message }) => | |||
<LinterResult>{ | <LinterResult>{ | |||
from: { | from: { | |||
line: locations![0].line - 1, | line: locations![0].line, | |||
ch: locations![0].column - 1, | ch: locations![0].column - 1, | |||
}, | }, | |||
to: { | to: { | |||
line: locations![0].line - 1, | line: locations![0].line - 1, | |||
ch: locations![0].column, | ch: locations![0].column, | |||
}, | }, | |||
message, | message, | |||
severity: "error", | severity: "error", | |||
} | } | |||
) | ) | |||
return Promise.resolve(results) | return Promise.resolve(results) | |||
} catch (e) { | } catch (e) { | |||
const err = e as GraphQLError | const err = e as GraphQLError | |||
return Promise.resolve([ | return Promise.resolve([ | |||
<LinterResult>{ | <LinterResult>{ | |||
from: { | from: { | |||
line: err.locations![0].line - 1, | line: err.locations![0].line, | |||
ch: err.locations![0].column - 1, | ch: err.locations![0].column - 1, | |||
}, | }, | |||
to: { | to: { | |||
line: err.locations![0].line - 1, | line: err.locations![0].line, | |||
ch: err.locations![0].column, | ch: err.locations![0].column, | |||
}, | }, | |||
message: err.message, | message: err.message, | |||
severity: "error", | severity: "error", | |||
}, | }, | |||
]) | ]) | |||
} | } | |||
} | } | |||
End of changes. 4 change blocks. | ||||
4 lines changed or deleted | 4 lines changed or added |