How can I use the IN filter with an Amplify GraphQL query?

How can I use the IN filter with an Amplify GraphQL query?


0

I’m trying to fetch multiple transactions with an array of IDs but i might do something wrong and I’m facing the following error :

ERROR   GraphQL Error: [
  {
    path: null,
    locations: [ [Object] ],
    message: "Validation error of type WrongType: argument 'filter.id' with value 'ObjectValue{objectFields=[ObjectField{name='id', value=ObjectValue{objectFields=[ObjectField{name='in', value=VariableReference{name='ids'}}]}}]}' contains a field not in 'ModelIDInput': 'in' @ 'listTransactions'"
  }
]

I’m using amplify.

This is the query:

const getTransactionsQuery = gql`
  query MyQuery($ids: [ID!]) {
    listTransactions(filter: { id: { in: $ids } }, limit: 100000000) {
      items {
        id
        eventId
        cycleId
        status
      }
    }
  }
`;

And this is the code that make the query :

const getTransactions = async (idList) => {

  const headers = {
    "x-api-key": "xxxx",
  };

  const data = {
    query: print(getTransactionsQuery),
    variables: { id: idList },
  };

  const graphqlData = await axios.post(
    "xxxx",
    data,
    {
      headers: headers,
    }
  );

  if (graphqlData.data.errors) {
    console.error("GraphQL Error:", graphqlData.data.errors);
    return null;
  }

  return graphqlData.data;
};

Do you see where the error is coming from?

New contributor

Thibaud Rouchon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


Load 2 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *