question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cannot pass value to parameter typed as ID

See original GitHub issue

Is it anyhow possible to pass a value to an ID typed parameter like below ?

I am trying to get repository information from GitHub. Therefore I created a parameterized query that expects $id of type ID!

Whenever I try to pass an ID Value like “MDEwOlJlcG9zaXRvcnk1NDc4MjE2MQ==” I get this:

Error: GraphQL error: Variable id of type ID! was provided invalid value

When I switch the parameter type from ID to String I get:

Error: GraphQL error: Type mismatch on variable $id and argument id (String / ID!)

Here’s the query definition:

private repositoryByIdQuery: any = gql`
      query repositoryById($id: ID!){
        node(id: $id){
           ...repositoryFragment
        }
      }
      
      fragment repositoryFragment on Repository {
        id
        description
        isPrivate
        name
      }
    `

Here’s the executing code:

public getById(id: string): Promise<any> {

  return new Promise<any>(
    (resolve, reject) => {
      this.githubClient.query({
            query: this.repositoryByIdQuery,
            variables:{
              id: id
            }
        }).then(
        ({loading, data}) => {
        if(!loading){
          console.log(data); 
          resolve(data);
        }
      },(reason) => {
        console.log("hello from rejected"+  reason);               
        reject(reason);
      });
    }
  )
}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8

github_iconTop GitHub Comments

9reactions
akashbdjcommented, Dec 2, 2017

@shtse8

If your schema looks something like this:

    type Repo {
        id: ID!
        .......
        .......
    }
    type Query {
        getRepo(id: ID!) : Repo
    }

You can execute your query like this:

    query getRepo($id: ID!) {
        getRepo(id: $id) {
              id
              .......
              .......
        }
    }

Make sure you use exact same type in query that you used while defining your schema, otherwise the GraphQL parser will yell at you.

Let me know if this helps. 😃

7reactions
ZacSweerscommented, Aug 14, 2017

Just answered it myself - I was querying with query repositoryById($id: String!){ instead of query repositoryById($id: ID!){

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to Pass Value through Parameter ID - SAP Community
Hi , I Cant able to Pass value from my zreport to Tcode "co40 " , Except "PLNUM ... Order type : Field...
Read more >
Passing variable name as id - javascript - Stack Overflow
You cannot pass what doesn't exist. To solve this, generate a name and an id to use. Also in your selectMainBrand function you...
Read more >
Parameters - AWS CloudFormation
Use parameters to pass values to your template when creating or updating a stack so that you can customize each stack deployment.
Read more >
The Go Programming Language Specification
It is an error if the constant value cannot be represented as a value of the respective type. If the type is a...
Read more >
Function pass by value vs. pass by reference
I will call what you are passing in a to a function the actual parameters, and where you ... This function, which swaps...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found