René's URL Explorer Experiment


Title: Variable validation broken when variables are used inside an input object value · Issue #3276 · graphql-java/graphql-java · GitHub

Open Graph Title: Variable validation broken when variables are used inside an input object value · Issue #3276 · graphql-java/graphql-java

X Title: Variable validation broken when variables are used inside an input object value · Issue #3276 · graphql-java/graphql-java

Description: Setup I'll use the following simple schema to illustrate the issue: type Query { items(pagination: Pagination = {limit: 10, offset: 0}): [String] } input Pagination { limit: Int offset: Int } While variables are commonly used as the whol...

Open Graph Description: Setup I'll use the following simple schema to illustrate the issue: type Query { items(pagination: Pagination = {limit: 10, offset: 0}): [String] } input Pagination { limit: Int offset: Int } While...

X Description: Setup I'll use the following simple schema to illustrate the issue: type Query { items(pagination: Pagination = {limit: 10, offset: 0}): [String] } input Pagination { limit: Int offset: Int } W...

Opengraph URL: https://github.com/graphql-java/graphql-java/issues/3276

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Variable validation broken when variables are used inside an input object value","articleBody":"**Setup**\r\n\r\nI'll use the following simple schema to illustrate the issue:\r\n\r\n```graphql\r\ntype Query {\r\n  items(pagination: Pagination = {limit: 10, offset: 0}): [String]\r\n}\r\n\r\ninput Pagination {\r\n  limit: Int\r\n  offset: Int\r\n}\r\n```\r\n\r\nWhile variables are commonly used as the whole argument value:\r\n\r\n```graphql\r\nquery Items($pagination: Pagination) {\r\n  items(pagination: $pagination) { #variable is the entire input object (Pagination)\r\n    ...\r\n  }\r\n}\r\n```\r\n\r\nthey can also be used  as the values of fields inside an input object:\r\n\r\n```graphql\r\nquery Items($limit: Int) {\r\n  items(pagination: {limit: $limit, offset: 0}) { #variable is only a part of the input\r\n    ...\r\n  }\r\n}\r\n```\r\n\r\nI've scoured the spec for a confirmation on whether this is indeed legal usage of variables and, while this situation is never directly addressed either way, the section on [Input Coercion](https://spec.graphql.org/draft/#example-704b8) lists the following examples which seem to indicate this is legitimate usage:\r\n\r\n```graphql Definition\r\ninput ExampleInputObject {\r\n  a: String\r\n  b: Int!\r\n}\r\n```\r\n\r\n| Literal Value            | Variables               | Coerced Value                        |\r\n| ------------------------ | ----------------------- | ------------------------------------ |\r\n| `{ a: $var, b: 123 }`    | `{ var: null }`         | `{ a: null, b: 123 }`                |\r\n| `{ b: $var }`            | `{ var: 123 }`          | `{ b: 123 }`                         |\r\n\r\n**The bug**\r\n\r\nWhen a variable is used inside an input object **_which has a default value_** (like in my `Pagination` example), graphql-java's variable type validation freaks out, because it compares the type of the variable (`Int`) against the default value of the entire argument (`Pagination`) [here](https://github.com/graphql-java/graphql-java/blob/7f229de387e5e515e99ff270a1d1b9316b6e0338/src/main/java/graphql/validation/rules/VariableTypesMatch.java#L63):\r\n\r\n```java\r\n//Notice the getValidationContext().getArgument()\r\nOptional\u003cInputValueWithState\u003e schemaDefault = Optional.ofNullable(getValidationContext().getArgument()).map(v -\u003e v.getArgumentDefaultValue());\r\n...  \r\n//expectedType is Int\r\nschemaDefaultValue = ValuesResolver.valueToLiteral(schemaDefault.get(), expectedType, getValidationContext().getGraphQLContext(), getValidationContext().getI18n().getLocale());\r\n```\r\n\r\n**To Reproduce**\r\n\r\nHere's a self-contained example:\r\n\r\n```java\r\nGraphQLSchema schema = GraphQLSchema.newSchema()\r\n                .query(GraphQLObjectType.newObject()\r\n                        .name(\"Query\")\r\n                        .field(items -\u003e items\r\n                                .name(\"items\")\r\n                                .type(GraphQLList.list(Scalars.GraphQLString))\r\n                                .argument(pagination -\u003e pagination\r\n                                        .name(\"pagination\")\r\n                                        //skipped adding the default limit/offset values as it doesn't change anything\r\n                                        .defaultValueProgrammatic(new HashMap\u003c\u003e())\r\n                                        .type(GraphQLInputObjectType.newInputObject()\r\n                                                .name(\"Pagination\")\r\n                                                .field(limit -\u003e limit\r\n                                                        .name(\"limit\")\r\n                                                        .type(Scalars.GraphQLInt))\r\n                                                .field(offset -\u003e offset\r\n                                                        .name(\"offset\")\r\n                                                        .type(Scalars.GraphQLInt))\r\n                                                .build())))\r\n                        .build())\r\n                .codeRegistry(GraphQLCodeRegistry.newCodeRegistry()\r\n                        .dataFetcher(FieldCoordinates.coordinates(\"Query\", \"items\"), (DataFetcher\u003c?\u003e) env -\u003e Collections.singletonList(\"test\"))\r\n                        .build())\r\n                .build();\r\n\r\n        GraphQL gql = GraphQLRuntime.newGraphQL(schema).build();\r\n\r\n        Map\u003cString, Object\u003e vars = new HashMap\u003c\u003e();\r\n        vars.put(\"limit\", 5);\r\n        vars.put(\"offset\", 0);\r\n\r\n        ExecutionInput in = ExecutionInput.newExecutionInput()\r\n                .query(\"query Items( $limit: Int, $offset: Int) {\\n\" +\r\n                        \"  items(\\n\" +\r\n                        \"    pagination: {limit: $limit, offset: $offset} \\n\" +\r\n                        \"  )\\n\" +\r\n                        \"}\")\r\n                .variables(vars)\r\n                .build();\r\n        ExecutionResult result = gql.execute(in);\r\n```\r\n\r\nLeads to:\r\n\r\n\u003e graphql.AssertException: Expected a value that can be converted to type 'Int' but it was a 'HashMap'\r\n","author":{"url":"https://github.com/kaqqao","@type":"Person","name":"kaqqao"},"datePublished":"2023-07-30T16:11:44.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/3276/graphql-java/issues/3276"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:0e5e520b-1bee-1199-5a75-9d41823b2859
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idE91E:17065F:832387:B03D8F:6A61868E
html-safe-nonce44db2587e82087f6d83851da1a08275ee0318fe0a700266d01feda85728db378
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFOTFFOjE3MDY1Rjo4MzIzODc6QjAzRDhGOjZBNjE4NjhFIiwidmlzaXRvcl9pZCI6IjI5NzI2MTM1NDI0MTg2Nzk0MzgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac686d1394dcdbdbbd545abe9b66062bc997bf3eb028d38569b37f4d555d57f8d0
hovercard-subject-tagissue:1827988843
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/graphql-java/graphql-java/3276/issue_layout
twitter:imagehttps://opengraph.githubassets.com/b0cf14495995a5807a80b842138bfb959c0f290ed5be40318c51534d74f0ba39/graphql-java/graphql-java/issues/3276
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/b0cf14495995a5807a80b842138bfb959c0f290ed5be40318c51534d74f0ba39/graphql-java/graphql-java/issues/3276
og:image:altSetup I'll use the following simple schema to illustrate the issue: type Query { items(pagination: Pagination = {limit: 10, offset: 0}): [String] } input Pagination { limit: Int offset: Int } While...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamekaqqao
hostnamegithub.com
expected-hostnamegithub.com
Nonec28c2f6607f2aacbd934868d997038895c9780d08babfe918550d73773326f4c
turbo-cache-controlno-preview
go-importgithub.com/graphql-java/graphql-java git https://github.com/graphql-java/graphql-java.git
octolytics-dimension-user_id14289921
octolytics-dimension-user_logingraphql-java
octolytics-dimension-repository_id38602457
octolytics-dimension-repository_nwographql-java/graphql-java
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id38602457
octolytics-dimension-repository_network_root_nwographql-java/graphql-java
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasecd05235d52ffb3318513d883a56c87a121015c8b
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/graphql-java/graphql-java/issues/3276#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgraphql-java%2Fgraphql-java%2Fissues%2F3276
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
Code QualityEnforce quality at mergehttps://github.com/features/code-quality
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgraphql-java%2Fgraphql-java%2Fissues%2F3276
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=graphql-java%2Fgraphql-java
Reloadhttps://github.com/graphql-java/graphql-java/issues/3276
Reloadhttps://github.com/graphql-java/graphql-java/issues/3276
Reloadhttps://github.com/graphql-java/graphql-java/issues/3276
Please reload this pagehttps://github.com/graphql-java/graphql-java/issues/3276
graphql-java https://github.com/graphql-java
graphql-javahttps://github.com/graphql-java/graphql-java
Notifications https://github.com/login?return_to=%2Fgraphql-java%2Fgraphql-java
Fork 1.1k https://github.com/login?return_to=%2Fgraphql-java%2Fgraphql-java
Star 6.2k https://github.com/login?return_to=%2Fgraphql-java%2Fgraphql-java
Code https://github.com/graphql-java/graphql-java
Issues 26 https://github.com/graphql-java/graphql-java/issues
Pull requests 11 https://github.com/graphql-java/graphql-java/pulls
Discussions https://github.com/graphql-java/graphql-java/discussions
Actions https://github.com/graphql-java/graphql-java/actions
Projects https://github.com/graphql-java/graphql-java/projects
Wiki https://github.com/graphql-java/graphql-java/wiki
Security and quality 0 https://github.com/graphql-java/graphql-java/security
Insights https://github.com/graphql-java/graphql-java/pulse
Code https://github.com/graphql-java/graphql-java
Issues https://github.com/graphql-java/graphql-java/issues
Pull requests https://github.com/graphql-java/graphql-java/pulls
Discussions https://github.com/graphql-java/graphql-java/discussions
Actions https://github.com/graphql-java/graphql-java/actions
Projects https://github.com/graphql-java/graphql-java/projects
Wiki https://github.com/graphql-java/graphql-java/wiki
Security and quality https://github.com/graphql-java/graphql-java/security
Insights https://github.com/graphql-java/graphql-java/pulse
Variable validation broken when variables are used inside an input object valuehttps://github.com/graphql-java/graphql-java/issues/3276#top
https://github.com/kaqqao
kaqqaohttps://github.com/kaqqao
on Jul 30, 2023https://github.com/graphql-java/graphql-java/issues/3276#issue-1827988843
Input Coercionhttps://spec.graphql.org/draft/#example-704b8
herehttps://github.com/graphql-java/graphql-java/blob/7f229de387e5e515e99ff270a1d1b9316b6e0338/src/main/java/graphql/validation/rules/VariableTypesMatch.java#L63
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.