Title: How to validate graphql query against the schema without execution? · Issue #2737 · graphql-java/graphql-java · GitHub
Open Graph Title: How to validate graphql query against the schema without execution? · Issue #2737 · graphql-java/graphql-java
X Title: How to validate graphql query against the schema without execution? · Issue #2737 · graphql-java/graphql-java
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: ParseAndValidate.validate Returns it as ...
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/issues/2737
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"How to validate graphql query against the schema without execution?","articleBody":"How to validate graphql query against the schema without execution?\r\n\r\nI tried below methods and all failed.\r\n\r\n@bbakerman @andimarek Any pointers?\r\n\r\n**Schema:** No mutations defined\r\n**Request:** mutation\r\n**Method:** ParseAndValidate.validate\r\nReturns it as `valid`. If I add mutation with dummy `FieldDefinition` it works. \r\n\r\n```\r\n\t@Test\r\n\tpublic void testValidateWithInvalidRequestUsingSchemaWithOnlyQueryAndInputWithMutation()\r\n\t\t\tthrows SchemaProblem, FileNotFoundException {\r\n\r\n\t\tInputStream in = this.getClass().getResourceAsStream(\"/only-query.graphql\");\r\n\r\n\t\tTypeDefinitionRegistry typeDefinitionRegistry = new SchemaParser().parse(in);\r\n\r\n\t\tGraphQLSchema schema = UnExecutableSchemaGenerator.makeUnExecutableSchema(typeDefinitionRegistry);\r\n\r\n\t\tString request = \"mutation MyMutation { mymutation }\";\r\n\r\n\t\tDocument inputDocument = new Parser().parseDocument(request);\r\n\r\n\t\tList\u003cValidationError\u003e errors = ParseAndValidate.validate(schema, inputDocument);\r\n\r\n\t\tassertEquals(1, errors.size());\r\n\t}\r\n\r\n```\r\n**Schema:** No mutations defined\r\n**Request:** mutation\r\n**Method:** ParseAndValidate.parseAndValidate\r\nReturns it as `valid`. If I add mutation with dummy `FieldDefinition` it works. \r\n```\r\n\t@Test\r\n\tpublic void testParseAndValidateWithInvalidRequestUsingSchemaWithOnlyQueryAndInputWithMutation()\r\n\t\t\tthrows SchemaProblem, FileNotFoundException {\r\n\t\tInputStream in = this.getClass().getResourceAsStream(\"/only-query.graphql\");\r\n\r\n\t\tTypeDefinitionRegistry typeDefinitionRegistry = new SchemaParser().parse(in);\r\n\r\n\t\tGraphQLSchema schema = UnExecutableSchemaGenerator.makeUnExecutableSchema(typeDefinitionRegistry);\r\n\r\n\t\tString request = \"mutation MyMutation { mymutation }\";\r\n\r\n\t\tExecutionInput input = ExecutionInput.newExecutionInput(request).build();\r\n\r\n\t\tParseAndValidateResult result = ParseAndValidate.parseAndValidate(schema, input);\r\n\r\n\t\tassertEquals(1, result.getErrors().size());\r\n\t}\r\n```\r\n**Schema:** Has mutation with not null return type\r\n**Request:** mutation\r\n**Method:** ParseAndValidate.parseAndValidate\r\nMockedWiringFactory is expecting the actual return.\r\n**Error:** \r\n```\r\njava.lang.AssertionError: expected same:\u003c\u003e was not:\u003c[graphql.execution.MissingRootTypeException: \r\nSchema is not configured for mutations.]\u003e\r\n```\r\n\r\n```\r\n\t@Test\r\n\tpublic void testMockedWiringFactoryWithValidRequest() throws SchemaProblem, FileNotFoundException {\r\n\t\tInputStream in = this.getClass().getResourceAsStream(\"/mutation-query.graphql\");\r\n\r\n\t\tTypeDefinitionRegistry typeDefinitionRegistry = new SchemaParser().parse(in);\r\n\r\n\t\tRuntimeWiring runtimeWiring = RuntimeWiring.newRuntimeWiring().wiringFactory(new MockedWiringFactory()).build();\r\n\r\n\t\tSchemaGenerator schemaGenerator = new SchemaGenerator();\r\n\r\n\t\tGraphQLSchema graphQLSchema = schemaGenerator.makeExecutableSchema(typeDefinitionRegistry, runtimeWiring);\r\n\r\n\t\tGraphQL graphQL = GraphQL.newGraphQL(graphQLSchema).build();\r\n\r\n\t\tString request = \"mutation MyMutation { mymutation }\";\r\n\r\n\t\tExecutionInput input = ExecutionInput.newExecutionInput(request).build();\r\n\r\n\t\tExecutionResult executionResult = graphQL.execute(input);\r\n\r\n\t\tassertSame(\"\", executionResult.getErrors().toString());\r\n\r\n\t\tassertEquals(0, executionResult.getErrors().size());\r\n\t}\r\n```\r\n\r\n\r\n\r\n","author":{"url":"https://github.com/arjunballa","@type":"Person","name":"arjunballa"},"datePublished":"2022-02-25T05:49:45.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/2737/graphql-java/issues/2737"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:6113b9d4-2bb6-71c7-f999-3d951dd05519 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A080:18226A:B3F447:EFD688:6A6192D3 |
| html-safe-nonce | 6c4e9c367af5c138aff56145c5b3feb08aa93a3ab49ddf277f05abec78932f73 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMDgwOjE4MjI2QTpCM0Y0NDc6RUZENjg4OjZBNjE5MkQzIiwidmlzaXRvcl9pZCI6IjI1NzcwOTYwMDg0OTQzMjIzODciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 17fbd3996ed80c35224dcf96f5fa3d5b02ca099ac208c7331c26d3fe5805f41e |
| hovercard-subject-tag | issue:1150070227 |
| github-keyboard-shortcuts | repository,issues,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/issues/show/graphql-java/graphql-java/2737/issue_layout |
| twitter:image | https://opengraph.githubassets.com/164604fa3cc2c95c7c3200614ac037998527d4a3fd7ff6c3c3ea1cf722fe51d4/graphql-java/graphql-java/issues/2737 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/164604fa3cc2c95c7c3200614ac037998527d4a3fd7ff6c3c3ea1cf722fe51d4/graphql-java/graphql-java/issues/2737 |
| 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 |
| og:author:username | arjunballa |
| hostname | github.com |
| expected-hostname | github.com |
| None | c28c2f6607f2aacbd934868d997038895c9780d08babfe918550d73773326f4c |
| 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 | cd05235d52ffb3318513d883a56c87a121015c8b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width