Title: Evidence of bug in query and validate that warrants further investigation · Issue #2740 · graphql-java/graphql-java · GitHub
Open Graph Title: Evidence of bug in query and validate that warrants further investigation · Issue #2740 · graphql-java/graphql-java
X Title: Evidence of bug in query and validate that warrants further investigation · Issue #2740 · graphql-java/graphql-java
Description: Discussed in #2739 Originally posted by arjunballa February 25, 2022 How to validate graphql query against the schema without execution? I tried below methods and all failed. @bbakerman @andimarek Any pointers? Schema: No mutations defin...
Open Graph Description: Discussed in #2739 Originally posted by arjunballa February 25, 2022 How to validate graphql query against the schema without execution? I tried below methods and all failed. @bbakerman @andimarek ...
X Description: Discussed in #2739 Originally posted by arjunballa February 25, 2022 How to validate graphql query against the schema without execution? I tried below methods and all failed. @bbakerman @andimarek ...
Opengraph URL: https://github.com/graphql-java/graphql-java/issues/2740
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Evidence of bug in query and validate that warrants further investigation","articleBody":"### Discussed in https://github.com/graphql-java/graphql-java/discussions/2739\r\n\r\n\u003cdiv type='discussions-op-text'\u003e\r\n\r\n\u003csup\u003eOriginally posted by **arjunballa** February 25, 2022\u003c/sup\u003e\r\nHow 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\u003c/div\u003e","author":{"url":"https://github.com/bbakerman","@type":"Person","name":"bbakerman"},"datePublished":"2022-02-25T06:22:51.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":7},"url":"https://github.com/2740/graphql-java/issues/2740"}
| 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:7b02224e-7335-b267-1953-6b5b397a68c3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9B10:3EDED5:1FE5BD:29CDFA:6A60254B |
| html-safe-nonce | fd8892acc62456cb5642c64655363fe9d6a59e5a430bdf1073e7995e17f3a4c5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5QjEwOjNFREVENToxRkU1QkQ6MjlDREZBOjZBNjAyNTRCIiwidmlzaXRvcl9pZCI6IjQwMjYwMTMxNjQzNTQxNTE3NTUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | e50e6c5310c0835050119663fc64c8fd6481ae96a5a9bb1472edb68dd76bbdaf |
| hovercard-subject-tag | issue:1150088823 |
| 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/2740/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f001c5c9ddb22b2851e075ea279d0f93614dc66d8b20bfde2167cd7742a3eef4/graphql-java/graphql-java/issues/2740 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f001c5c9ddb22b2851e075ea279d0f93614dc66d8b20bfde2167cd7742a3eef4/graphql-java/graphql-java/issues/2740 |
| og:image:alt | Discussed in #2739 Originally posted by arjunballa February 25, 2022 How to validate graphql query against the schema without execution? I tried below methods and all failed. @bbakerman @andimarek ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | bbakerman |
| hostname | github.com |
| expected-hostname | github.com |
| None | 60da8c2a42fa2bbf5f7567474990ec467836a84444262a58e200fa91b7f3d2d0 |
| 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 | 9824515e740d83d5eb82168a089b806ab0fe04a1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width