-1

I have a basic graphql query as a string which executes as expected before I try to modify it and add input variables (the query is long so I will only include the beginning of the query which is where the variable needs to be inserted)

query {
  vessels {
    pageInfo {
      hasNextPage
      endCursor
    }
    nodes {
...

This works and returns the expected response:

try:
    response = client.execute(gql(query))
except BaseException as e:
    logger.error(e)
    raise

The schema allows for specific vessels to be queried, so I followed the example in the gql documentation here to input a list of variables

query {
  vessels (mmsi: $code ) {
    pageInfo {
      hasNextPage
      endCursor
    }
    nodes {
...

However, this does not work and raises an error:

params = {"code": [775903449, 775982824]}

try:
    response = client.execute(gql(query), variable_values=params)
except BaseException as e:
    logger.error(e)
    raise
graphql.error.base.GraphQLError: Variable "$code" is not defined.

What am I doing wrong here with the variable insertion/replacment into the query string? Any help would be appreciated!

iskandarblue
  • 7,208
  • 15
  • 60
  • 130

1 Answers1

0

Can answer my own question - one needs to define the variable in the first part of the query!

query ($code: [MMSI!]) {
  vessels (mmsi: $code ){
    pageInfo {
      hasNextPage
      endCursor
    }
    nodes {
iskandarblue
  • 7,208
  • 15
  • 60
  • 130