atulmy/gql-query-builder

Add enum

Opened this issue · 6 comments

i have some query that need add Enum like that:

{
  diagnostic__defects(page: 1, orderBy: [{field: IS_FUNCTIONAL_DEFECT, order: DESC}]) {
    data {
      id
      name
    }
  }
}

IS_FUNCTIONAL_DEFECT and DESC are ENUM, can't be wrapped by quote

@felipe-gustavo feel free to open a PR for this use case.

@felipe-gustavo can you try the following command

const gqlquery = query([
  {
    operation: "diagnostic__defects",
    variables: {
      page: {
        value: 1
      },
      orderBy:{
        list: true,
        type: 'type your order input value here, defined in the schema',
        value: {field: 'IS_FUNCTIONAL_DEFECT', order: 'DESC'}
      }
    },
    fields: [{'data':['id','name']}]
  },
]);

@felipe-gustavo Atm there is no way to embed argument values directly, but hopefully the above will work, otherwise I'll send a PR to embed argument values directly without using variables

@Devorein @atulmy I have the same use case. The above command you posted did not work for me. Has there been any update on this?

Same here.

To spare the sanity of anyone else who might resort to reading the graphql spec like me, no the graphql spec doesn't say that the server must accept strings in the variables transport for enum values. It specifically says it may accept strings. The relevant section is here: https://spec.graphql.org/October2021/#sec-Enums.Input-Coercion

I think I have enough time today to implement a PR for this so I'm working on it now.