question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mutations that use Enums

See original GitHub issue

Mutations that use Enum values for inputs do not work as it creates the query string with double quotes around the Enum types

GraphQL schema

type ProviderHours {
  day: DayOfWeek!
  isOpen: Boolean!
}

enum DayOfWeek {
  MONDAY
  TUESDAY
   ...
}

Node

let mutation = {
  mutation: {
    updateProviderHours: {
      __args: {
        id: 1,
        input: [{
          day: 'MONDAY',
          isOpen: false
        }]
      },
      hours: {
        day: true,
        isOpen: true
      }
    }
  }
}
mutation = jsonToGraphQLQuery(mutation)

the above gives me

mutation { updateProviderHours (providerId: 1, input: [{day: "MONDAY", isOpen: false}]) { hours { day isOpen } } }

using “MONDAY” in the string.

Is there anyway to not quote these values when they’re enumerators?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
dupskicommented, Mar 27, 2018

Published v1.2.0 which supports this feature @steezeburger . Cheers @douglaseggleton 😃

import { jsonToGraphQLQuery, EnumType } from 'json-to-graphql-query';

const query = {
    query: {
        Posts: {
            __args: {
                where: { id: 2 }
                orderBy: 'post_date',
                status: new EnumType('PUBLISHED')
            },
            id: true,
            title: true,
            post_date: true
        }
    }
};
1reaction
douglaseggletoncommented, Mar 27, 2018
Read more comments on GitHub >

github_iconTop Results From Across the Web

Mutations that use Enums · Issue #2 · vkolgi/json-to-graphql ...
Mutations that use Enum values for inputs do not work as it creates the query string with double quotes around the Enum types...
Read more >
How to use GraphQL enum and its best practices - Medium
In the following image, we illustrate the hierarchical tree graph of the response for our queries and mutations. Enum Types. Enums are basically...
Read more >
GraphQL - Passing an enum value directly to a mutation as an ...
Show activity on this post. use the enum variable name as defined in the mutation and send it to Graphql, like I have...
Read more >
What you need to know about GraphQL enums
Learn how GraphQL enums can help you build more robust and discoverable APIs, create simple interfaces, maintain slim resolvers, and more.
Read more >
How to use GraphQL enum and its best practices
The enum class allows us to map enum values to internal values represented by integers (or different strings etc.). By defining enumerated ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found