graphql / vscode-graphql

MIGRATED: VSCode GraphQL extension (autocompletion, go-to definition, syntax highlighting)
https://marketplace.visualstudio.com/items?itemName=Prisma.vscode-graphql
MIT License
555 stars 71 forks source link

Cannot build invalid schemas (graphql-config) #208

Closed DanielRosenwasser closed 4 years ago

DanielRosenwasser commented 4 years ago

Actual Behavior

Console crashes galore.

Expected Behavior

Type errors, completions, functioning behavior.

Specifications

Steps to Reproduce the Problem Or Description

# schemas/asd.graphql
type User {
    name: String!

}

type Yadda {
    user: User
}
# .graphqlrc
{
  schema: ['schemas/**/*.graphql'],
  documents: ["**/*.{graphql,js,ts,jsx,tsx}"],
}
9/1/2020, 3:29:36 PM [4] (pid: 11860) graphql-language-service-usage-logs: {"type":"usage","messageType":"initialize"}

undefined
9/1/2020, 3:29:36 PM [1] (pid: 11860) graphql-language-service-usage-logs: Error: Unknown type "Us".

undefined
(node:11860) UnhandledPromiseRejectionWarning: Error: Unknown type "Us".
    at assertValidSDL (c:\Users\Daniel\.vscode-insiders\extensions\prisma.vscode-graphql-0.3.1\node_modules\graphql\validation\validate.js:107:11)
    at Object.buildASTSchema (c:\Users\Daniel\.vscode-insiders\extensions\prisma.vscode-graphql-0.3.1\node_modules\graphql\utilities\buildASTSchema.js:45:34)
    at makeSchema (c:\Users\Daniel\.vscode-insiders\extensions\prisma.vscode-graphql-0.3.1\node_modules\@graphql-tools\merge\index.cjs.js:954:99)
    at Object.mergeSchemasAsync (c:\Users\Daniel\.vscode-insiders\extensions\prisma.vscode-graphql-0.3.1\node_modules\@graphql-tools\merge\index.cjs.js:945:12)
    at async Object.loadSchema (c:\Users\Daniel\.vscode-insiders\extensions\prisma.vscode-graphql-0.3.1\node_modules\@graphql-tools\load\index.cjs.js:650:20)
    at async GraphQLCache.getSchema (c:\Users\Daniel\.vscode-insiders\extensions\prisma.vscode-graphql-0.3.1\node_modules\graphql-language-service-server\dist\GraphQLCache.js:256:26)
(node:11860) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:11860) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:11860) UnhandledPromiseRejectionWarning: Error: Unknown type "Us".
    at assertValidSDL (c:\Users\Daniel\.vscode-insiders\extensions\prisma.vscode-graphql-0.3.1\node_modules\graphql\validation\validate.js:107:11)
    at Object.buildASTSchema (c:\Users\Daniel\.vscode-insiders\extensions\prisma.vscode-graphql-0.3.1\node_modules\graphql\utilities\buildASTSchema.js:45:34)
    at makeSchema (c:\Users\Daniel\.vscode-insiders\extensions\prisma.vscode-graphql-0.3.1\node_modules\@graphql-tools\merge\index.cjs.js:954:99)
    at Object.mergeSchemasAsync (c:\Users\Daniel\.vscode-insiders\extensions\prisma.vscode-graphql-0.3.1\node_modules\@graphql-tools\merge\index.cjs.js:945:12)
    at async Object.loadSchema (c:\Users\Daniel\.vscode-insiders\extensions\prisma.vscode-graphql-0.3.1\node_modules\@graphql-tools\load\index.cjs.js:650:20)
    at async GraphQLCache.getSchema (c:\Users\Daniel\.vscode-insiders\extensions\prisma.vscode-graphql-0.3.1\node_modules\graphql-language-service-server\dist\GraphQLCache.js:256:26)
(node:11860) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
[Error - 3:29:49 PM] Request textDocument/completion failed.
  Message: Request textDocument/completion failed with message: Unknown type "Us".
  Code: -32603 
(node:11860) UnhandledPromiseRejectionWarning: Error: Unknown type "Us".
    at assertValidSDL (c:\Users\Daniel\.vscode-insiders\extensions\prisma.vscode-graphql-0.3.1\node_modules\graphql\validation\validate.js:107:11)
    at Object.buildASTSchema (c:\Users\Daniel\.vscode-insiders\extensions\prisma.vscode-graphql-0.3.1\node_modules\graphql\utilities\buildASTSchema.js:45:34)
    at makeSchema (c:\Users\Daniel\.vscode-insiders\extensions\prisma.vscode-graphql-0.3.1\node_modules\@graphql-tools\merge\index.cjs.js:954:99)
    at Object.mergeSchemasAsync (c:\Users\Daniel\.vscode-insiders\extensions\prisma.vscode-graphql-0.3.1\node_modules\@graphql-tools\merge\index.cjs.js:945:12)
    at async Object.loadSchema (c:\Users\Daniel\.vscode-insiders\extensions\prisma.vscode-graphql-0.3.1\node_modules\@graphql-tools\load\index.cjs.js:650:20)
    at async GraphQLCache.getSchema (c:\Users\Daniel\.vscode-insiders\extensions\prisma.vscode-graphql-0.3.1\node_modules\graphql-language-service-server\dist\GraphQLCache.js:256:26)
(node:11860) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
(node:11860) UnhandledPromiseRejectionWarning: Error: Type "User" already exists in the schema. It cannot also be defined in this type definition.

Field "User.name" already exists in the schema. It cannot also be defined in this type extension.

Type "User" already exists in the schema. It cannot also be defined in this type definition.

Field "User.name" already exists in the schema. It cannot also be defined in this type extension.

Type "Yadda" already exists in the schema. It cannot also be defined in this type definition.

Field "Yadda.user" already exists in the schema. It cannot also be defined in this type extension.

Unknown type "Us".
    at assertValidSDLExtension (c:\Users\Daniel\.vscode-insiders\extensions\prisma.vscode-graphql-0.3.1\node_modules\graphql\validation\validate.js:124:11)
    at Object.extendSchema (c:\Users\Daniel\.vscode-insiders\extensions\prisma.vscode-graphql-0.3.1\node_modules\graphql\utilities\extendSchema.js:77:43)
    at GraphQLCache._extendSchema (c:\Users\Daniel\.vscode-insiders\extensions\prisma.vscode-graphql-0.3.1\node_modules\graphql-language-service-server\dist\GraphQLCache.js:567:26)
    at GraphQLCache.getSchema (c:\Users\Daniel\.vscode-insiders\extensions\prisma.vscode-graphql-0.3.1\node_modules\graphql-language-service-server\dist\GraphQLCache.js:270:31)
acao commented 4 years ago

looks like you are having an issue with graphql-config. might be best to open this issue in that repo, however they will tell you that the result of your schema pointers needs to be a valid schema. this means no duplicate types , or undefined types!

acao commented 4 years ago

anyways, good luck with your issue! it would be labourious for us to trap this error handled by graphql-config and provide any other kind of error output to make this clearer.

if you need better information about why your schema pointers are invalid, then opening a ticket for https://github.com/kamilkisiela/graphql-config would be your best bet!

DanielRosenwasser commented 4 years ago

Hey, thanks for looking into this. My take is that the language service should be more resilient to invalid input, whether that's in config or in incorrect schema. If the underlying dependency can't handle invalid config or schema, will it ever be able to provide code completion in SDL files? If not, is that in the long-term scope of the project? Sorry ahead of time if I've missed something.

acao commented 4 years ago

yes, it can handle invalid schema and provide completion when editing SDL files, and i will expose this option in the next patch release. it's just that certain types of issues will break the parser or other lower levels of logic, which are hard to avoid. I will keep this in mind for the future, as it would be ideal to highlight duplicate types in SDL files, etc. Using multiple SDL files for the entire schema source isn't exactly the most popular way to do things, so we will be following up with improved support for that where possible once we ensure that programmatic schema users needs are met