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

array passed as variable is treated as comma-separated string in payload #7349

Closed
adammo94 opened this issue Nov 20, 2020 · 2 comments
Closed

Comments

@adammo94
Copy link

Hi, I have a following problem I'm trying to pass a table of strings (sensorId and avgSensorId in my case) in query, let's say: ["aaa","bbb"] in query input I have it as [String]! however when it performs query when I check in network tab in inspector it shows "aaa,bbb" which fails query for more than one element in the table. I tried passing it as [sensorId ], [...sensorId ] and simply sensorId , however it always gives a payload of comma separated values in string. What could be the solution to this?

const { loading, error, data, refetch } = useQuery(SINGLE_CHART, { variables: { start: `${start}`, stop: `${stop}`, type: `${type}`, sensorId: `${sensorId}`,avgSensorId: `${avgSensorId}` }, fetchPolicy: "no-cache" });
export const SINGLE_CHART = gql backtick
  query chart($start: String!, $stop: String!, $type: String!, $sensorId: [String]!, $avgSensorId: [String]!){
    chart(input: {
      start: $start,
      stop: $stop,
      type: $type,
      sensorId: $sensorId,
      avgSensorId: $avgSensorId
    }) {
        labels
        datasets {
          label
          data
          backgroundColor
          borderColor
          borderWidth
        }
    }
  }
backtick
@devkot
Copy link

devkot commented Nov 21, 2020

Hi @adammo94, your issue here seems to be related to JS template literals instead of GQL.

For example, if sensorId = ["a", "b"] then ${sensorId} would return "a,b".

Luckily, you don't need to use template literals to pass the variables to your GQL query and you can pass the sensorId variable instead.

So your query variables could look like:
{ variables: { sensorId: sensorId } } or using the shorthand { variables: { sensorId } }

@hwillson
Copy link
Member

It doesn't sound like there is an outstanding issue here, so closing. Thanks!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants