1

I'd like to pass the following key:value pairs to a GraphQL query. I imagine it working something like this, but have been unable to find a way to achieve this.

query myPortfolio {
  portfolio(holdings: {"btc": 0.12, "ltc": 12.1}) {
    # ...
  }
}

I attempted to create a special type and pass it as an array, but this failed compilation.

type Holding {
  coin: String!
  amount: Float!
}

type Query {  
  portfolio(holdings: [Holding!]): Portfolio!
}

Error: The type of Query.portfolio(holdings:) must be Input Type but got: [Holding!].

1 Answer 1

1

like the message says, the arguments needs to be of input type. Change your schema to something like

type Holding {
  coin: String!
  amount: Float!
}

input HoldingInput{
  coin: String!
  amount: Float!
}

type Query {  
  portfolio(holdings: [HoldingInput!]): Portfolio!
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.