Title: How to validate graphql query against the schema without execution? · graphql-java/graphql-java · Discussion #2739 · GitHub
Open Graph Title: How to validate graphql query against the schema without execution? · graphql-java/graphql-java · Discussion #2739
X Title: How to validate graphql query against the schema without execution? · graphql-java/graphql-java · Discussion #2739
Description: How to validate graphql query against the schema without execution?
Open Graph Description: How to validate graphql query against the schema without execution? I tried below methods and all failed. @bbakerman @andimarek Any pointers? Schema: No mutations defined Request: mutation Method: ...
X Description: How to validate graphql query against the schema without execution? I tried below methods and all failed. @bbakerman @andimarek Any pointers? Schema: No mutations defined Request: mutation Method: ...
Opengraph URL: https://github.com/graphql-java/graphql-java/discussions/2739
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"QAPage","mainEntity":{"@type":"Question","name":"How to validate graphql query against the schema without execution?","text":"\u003cp dir=\"auto\"\u003eHow to validate graphql query against the schema without execution?\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eI tried below methods and all failed.\u003c/p\u003e\n\u003cp dir=\"auto\"\u003e\u003ca class=\"user-mention notranslate\" data-hovercard-type=\"user\" data-hovercard-url=\"/users/bbakerman/hovercard\" data-octo-click=\"hovercard-link-click\" data-octo-dimensions=\"link_type:self\" href=\"https://github.com/bbakerman\"\u003e@bbakerman\u003c/a\u003e \u003ca class=\"user-mention notranslate\" data-hovercard-type=\"user\" data-hovercard-url=\"/users/andimarek/hovercard\" data-octo-click=\"hovercard-link-click\" data-octo-dimensions=\"link_type:self\" href=\"https://github.com/andimarek\"\u003e@andimarek\u003c/a\u003e Any pointers?\u003c/p\u003e\n\u003cp dir=\"auto\"\u003e\u003cstrong\u003eSchema:\u003c/strong\u003e No mutations defined\u003cbr\u003e\n\u003cstrong\u003eRequest:\u003c/strong\u003e mutation\u003cbr\u003e\n\u003cstrong\u003eMethod:\u003c/strong\u003e ParseAndValidate.validate\u003cbr\u003e\nReturns it as \u003ccode class=\"notranslate\"\u003evalid\u003c/code\u003e. If I add mutation with dummy \u003ccode class=\"notranslate\"\u003eFieldDefinition\u003c/code\u003e it works.\u003c/p\u003e\n\u003cdiv class=\"snippet-clipboard-content notranslate position-relative overflow-auto\" data-snippet-clipboard-copy-content=\"\t@Test\n\tpublic void testValidateWithInvalidRequestUsingSchemaWithOnlyQueryAndInputWithMutation()\n\t\t\tthrows SchemaProblem, FileNotFoundException {\n\n\t\tInputStream in = this.getClass().getResourceAsStream(\u0026quot;/only-query.graphql\u0026quot;);\n\n\t\tTypeDefinitionRegistry typeDefinitionRegistry = new SchemaParser().parse(in);\n\n\t\tGraphQLSchema schema = UnExecutableSchemaGenerator.makeUnExecutableSchema(typeDefinitionRegistry);\n\n\t\tString request = \u0026quot;mutation MyMutation { mymutation }\u0026quot;;\n\n\t\tDocument inputDocument = new Parser().parseDocument(request);\n\n\t\tList\u0026lt;ValidationError\u0026gt; errors = ParseAndValidate.validate(schema, inputDocument);\n\n\t\tassertEquals(1, errors.size());\n\t}\n\"\u003e\u003cpre class=\"notranslate\"\u003e\u003ccode class=\"notranslate\"\u003e\t@Test\n\tpublic void testValidateWithInvalidRequestUsingSchemaWithOnlyQueryAndInputWithMutation()\n\t\t\tthrows SchemaProblem, FileNotFoundException {\n\n\t\tInputStream in = this.getClass().getResourceAsStream(\"/only-query.graphql\");\n\n\t\tTypeDefinitionRegistry typeDefinitionRegistry = new SchemaParser().parse(in);\n\n\t\tGraphQLSchema schema = UnExecutableSchemaGenerator.makeUnExecutableSchema(typeDefinitionRegistry);\n\n\t\tString request = \"mutation MyMutation { mymutation }\";\n\n\t\tDocument inputDocument = new Parser().parseDocument(request);\n\n\t\tList\u0026lt;ValidationError\u0026gt; errors = ParseAndValidate.validate(schema, inputDocument);\n\n\t\tassertEquals(1, errors.size());\n\t}\n\n\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003e\u003cstrong\u003eSchema:\u003c/strong\u003e No mutations defined\u003cbr\u003e\n\u003cstrong\u003eRequest:\u003c/strong\u003e mutation\u003cbr\u003e\n\u003cstrong\u003eMethod:\u003c/strong\u003e ParseAndValidate.parseAndValidate\u003cbr\u003e\nReturns it as \u003ccode class=\"notranslate\"\u003evalid\u003c/code\u003e. If I add mutation with dummy \u003ccode class=\"notranslate\"\u003eFieldDefinition\u003c/code\u003e it works.\u003c/p\u003e\n\u003cdiv class=\"snippet-clipboard-content notranslate position-relative overflow-auto\" data-snippet-clipboard-copy-content=\"\t@Test\n\tpublic void testParseAndValidateWithInvalidRequestUsingSchemaWithOnlyQueryAndInputWithMutation()\n\t\t\tthrows SchemaProblem, FileNotFoundException {\n\t\tInputStream in = this.getClass().getResourceAsStream(\u0026quot;/only-query.graphql\u0026quot;);\n\n\t\tTypeDefinitionRegistry typeDefinitionRegistry = new SchemaParser().parse(in);\n\n\t\tGraphQLSchema schema = UnExecutableSchemaGenerator.makeUnExecutableSchema(typeDefinitionRegistry);\n\n\t\tString request = \u0026quot;mutation MyMutation { mymutation }\u0026quot;;\n\n\t\tExecutionInput input = ExecutionInput.newExecutionInput(request).build();\n\n\t\tParseAndValidateResult result = ParseAndValidate.parseAndValidate(schema, input);\n\n\t\tassertEquals(1, result.getErrors().size());\n\t}\"\u003e\u003cpre class=\"notranslate\"\u003e\u003ccode class=\"notranslate\"\u003e\t@Test\n\tpublic void testParseAndValidateWithInvalidRequestUsingSchemaWithOnlyQueryAndInputWithMutation()\n\t\t\tthrows SchemaProblem, FileNotFoundException {\n\t\tInputStream in = this.getClass().getResourceAsStream(\"/only-query.graphql\");\n\n\t\tTypeDefinitionRegistry typeDefinitionRegistry = new SchemaParser().parse(in);\n\n\t\tGraphQLSchema schema = UnExecutableSchemaGenerator.makeUnExecutableSchema(typeDefinitionRegistry);\n\n\t\tString request = \"mutation MyMutation { mymutation }\";\n\n\t\tExecutionInput input = ExecutionInput.newExecutionInput(request).build();\n\n\t\tParseAndValidateResult result = ParseAndValidate.parseAndValidate(schema, input);\n\n\t\tassertEquals(1, result.getErrors().size());\n\t}\n\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003e\u003cstrong\u003eSchema:\u003c/strong\u003e Has mutation with not null return type\u003cbr\u003e\n\u003cstrong\u003eRequest:\u003c/strong\u003e mutation\u003cbr\u003e\n\u003cstrong\u003eMethod:\u003c/strong\u003e ParseAndValidate.parseAndValidate\u003cbr\u003e\nMockedWiringFactory is expecting the actual return.\u003cbr\u003e\n\u003cstrong\u003eError:\u003c/strong\u003e\u003c/p\u003e\n\u003cdiv class=\"snippet-clipboard-content notranslate position-relative overflow-auto\" data-snippet-clipboard-copy-content=\"java.lang.AssertionError: expected same:\u0026lt;\u0026gt; was not:\u0026lt;[graphql.execution.MissingRootTypeException: \nSchema is not configured for mutations.]\u0026gt;\"\u003e\u003cpre class=\"notranslate\"\u003e\u003ccode class=\"notranslate\"\u003ejava.lang.AssertionError: expected same:\u0026lt;\u0026gt; was not:\u0026lt;[graphql.execution.MissingRootTypeException: \nSchema is not configured for mutations.]\u0026gt;\n\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e\n\u003cdiv class=\"snippet-clipboard-content notranslate position-relative overflow-auto\" data-snippet-clipboard-copy-content=\"\t@Test\n\tpublic void testMockedWiringFactoryWithValidRequest() throws SchemaProblem, FileNotFoundException {\n\t\tInputStream in = this.getClass().getResourceAsStream(\u0026quot;/mutation-query.graphql\u0026quot;);\n\n\t\tTypeDefinitionRegistry typeDefinitionRegistry = new SchemaParser().parse(in);\n\n\t\tRuntimeWiring runtimeWiring = RuntimeWiring.newRuntimeWiring().wiringFactory(new MockedWiringFactory()).build();\n\n\t\tSchemaGenerator schemaGenerator = new SchemaGenerator();\n\n\t\tGraphQLSchema graphQLSchema = schemaGenerator.makeExecutableSchema(typeDefinitionRegistry, runtimeWiring);\n\n\t\tGraphQL graphQL = GraphQL.newGraphQL(graphQLSchema).build();\n\n\t\tString request = \u0026quot;mutation MyMutation { mymutation }\u0026quot;;\n\n\t\tExecutionInput input = ExecutionInput.newExecutionInput(request).build();\n\n\t\tExecutionResult executionResult = graphQL.execute(input);\n\n\t\tassertSame(\u0026quot;\u0026quot;, executionResult.getErrors().toString());\n\n\t\tassertEquals(0, executionResult.getErrors().size());\n\t}\"\u003e\u003cpre class=\"notranslate\"\u003e\u003ccode class=\"notranslate\"\u003e\t@Test\n\tpublic void testMockedWiringFactoryWithValidRequest() throws SchemaProblem, FileNotFoundException {\n\t\tInputStream in = this.getClass().getResourceAsStream(\"/mutation-query.graphql\");\n\n\t\tTypeDefinitionRegistry typeDefinitionRegistry = new SchemaParser().parse(in);\n\n\t\tRuntimeWiring runtimeWiring = RuntimeWiring.newRuntimeWiring().wiringFactory(new MockedWiringFactory()).build();\n\n\t\tSchemaGenerator schemaGenerator = new SchemaGenerator();\n\n\t\tGraphQLSchema graphQLSchema = schemaGenerator.makeExecutableSchema(typeDefinitionRegistry, runtimeWiring);\n\n\t\tGraphQL graphQL = GraphQL.newGraphQL(graphQLSchema).build();\n\n\t\tString request = \"mutation MyMutation { mymutation }\";\n\n\t\tExecutionInput input = ExecutionInput.newExecutionInput(request).build();\n\n\t\tExecutionResult executionResult = graphQL.execute(input);\n\n\t\tassertSame(\"\", executionResult.getErrors().toString());\n\n\t\tassertEquals(0, executionResult.getErrors().size());\n\t}\n\u003c/code\u003e\u003c/pre\u003e\u003c/div\u003e","upvoteCount":1,"answerCount":4,"acceptedAnswer":{"@type":"Answer","text":"\u003cp dir=\"auto\"\u003eFYI - bug created \u003ca class=\"issue-link js-issue-link\" data-error-text=\"Failed to load title\" data-id=\"1150088823\" data-permission-text=\"Title is private\" data-url=\"https://github.com/graphql-java/graphql-java/issues/2740\" data-hovercard-type=\"issue\" data-hovercard-url=\"/graphql-java/graphql-java/issues/2740/hovercard\" href=\"https://github.com/graphql-java/graphql-java/issues/2740\"\u003e#2740\u003c/a\u003e\u003c/p\u003e","upvoteCount":1,"url":"https://github.com/graphql-java/graphql-java/discussions/2739#discussioncomment-2253251"}}}
| route-pattern | /_view_fragments/Voltron::DiscussionsFragmentsController/show/:user_id/:repository/:discussion_number/discussion_layout(.:format) |
| route-controller | voltron_discussions_fragments |
| route-action | discussion_layout |
| fetch-nonce | v2:e5459d12-2bd1-fcf6-28cb-ac888488c613 |
| current-catalog-service-hash | 9f0abe34da433c9b6db74bffa2466494a717b579a96b30a5d252e5090baea7be |
| request-id | DB56:21CBBC:CEC67:10BF00:6A6142B3 |
| html-safe-nonce | df2eb528490e723920c1a20457f6bf70eb6936b9c88d61b890ca1d9b05d167f2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQjU2OjIxQ0JCQzpDRUM2NzoxMEJGMDA6NkE2MTQyQjMiLCJ2aXNpdG9yX2lkIjoiMzU4ODIwMTY4MzAxMTg0NjgzNSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | cb5faf1e85ea298a8f57903e638791bd1846fafcc4d60f2559f4e69c31a6d40b |
| hovercard-subject-tag | discussion:3900716 |
| github-keyboard-shortcuts | repository,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/Voltron::DiscussionsFragmentsController/show/graphql-java/graphql-java/2739/discussion_layout |
| twitter:image | https://opengraph.githubassets.com/30e6d56c4ce14aeebcd80c0b3538b1d7dcf8707d00c3d2d42d91f403ce572406/graphql-java/graphql-java/discussions/2739 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/30e6d56c4ce14aeebcd80c0b3538b1d7dcf8707d00c3d2d42d91f403ce572406/graphql-java/graphql-java/discussions/2739 |
| og:image:alt | How to validate graphql query against the schema without execution? I tried below methods and all failed. @bbakerman @andimarek Any pointers? Schema: No mutations defined Request: mutation Method: ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 358090e896abe1815bef70fcaae0a12d8ebf315874207428312daf7419e9c7c9 |
| turbo-cache-control | no-preview |
| go-import | github.com/graphql-java/graphql-java git https://github.com/graphql-java/graphql-java.git |
| octolytics-dimension-user_id | 14289921 |
| octolytics-dimension-user_login | graphql-java |
| octolytics-dimension-repository_id | 38602457 |
| octolytics-dimension-repository_nwo | graphql-java/graphql-java |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 38602457 |
| octolytics-dimension-repository_network_root_nwo | graphql-java/graphql-java |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 87be91c8b3c813d60ac5c8ece422529a03a7e332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width