Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to populate Int Variables in Typescript #343

Open
digimangos opened this issue May 13, 2022 · 2 comments
Open

How to populate Int Variables in Typescript #343

digimangos opened this issue May 13, 2022 · 2 comments
Labels
Status: Up for grabs Issues that are ready to be worked on by anyone Type: Support Any questions, information, or general needs around the SDK or GitHub APIs

Comments

@digimangos
Copy link

I'm trying to use a query which has an "Int!" variable, but this is always being sent as a string.

await this.getOctokit().graphql(
          `query ($orgName: String!, $projectNumber: Int!){
            organization(login: $orgName) {
                projectNext(number: $projectNumber) {
                  id
                }
            }}`
        ,{
         orgName,
         projectNumber
        })

projectNumber is defined as projectNumber: number

But the resultant graphQL query is sent as a string:

    "request": {
        "query": "query ($orgName: String!, $projectNumber: Int!){\n            organization(login: $orgName) {\n                projectNext(number: $projectNumber) {\n                  id\n                }\n            }}",
        "variables": {
            "orgName": "myorg",
            "projectNumber": "4"
        }
    }

which returns the error:

        {
            "extensions": {
                "value": "4",
                "problems": [
                    {
                        "path": [],
                        "explanation": "Could not coerce value \"4\" to Int"
                    }
                ]
            },
            "locations": [
                {
                    "line": 1,
                    "column": 27
                }
            ],
            "message": "Variable $projectNumber of type Int! was provided invalid value"
        }

Is it possible for the variable to be resolved as "projectNumber": 4? I notice the example in the README.md - Variables, doesn't show the population of an Int variable instead its defaulted in. So perhaps it's not supported?

@nickfloyd nickfloyd added the Type: Support Any questions, information, or general needs around the SDK or GitHub APIs label Jun 30, 2022
@peter-evans
Copy link

I've run into this issue. Is there a solution or any workaround?

@peter-evans
Copy link

Well I guess the workaround is to use template literals.

    const query = `
      query($owner: String!, $repo: String!) {
        repository(owner: $owner, name: $repo) {
          pullRequest(number: ${pullNumber}) {
            id
          }
        }
      }
    `

@kfcampbell kfcampbell added Status: Up for grabs Issues that are ready to be worked on by anyone Priority: Normal labels Apr 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Up for grabs Issues that are ready to be worked on by anyone Type: Support Any questions, information, or general needs around the SDK or GitHub APIs
Projects
None yet
Development

No branches or pull requests

4 participants