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.

[flow] enums with underscore produce an invalid object key

See original GitHub issue

Describe the bug

When you use _ as a value on a graphql enum, the flow plugin fails to generate a valid object definition for such enum. It creates an object with a missing key (take a look below for examples).

To Reproduce Use the following enum on a Graphql schema:

enum Gender {
    M
    F
    _
}
  1. My GraphQL schema:
schema {
  query: Query
  mutation: Mutation
}

type Mutation {
  # Pay schedules
  addUser(input: addUserInput!): User
}

type Query {
  node(id: ID!): Node
  viewer: Viewer
}

interface Node {
  id: ID!
}

type Viewer implements Node {
  id: ID!
  user(id: ID!): User!
}

input addUserInput {
    name: String!
    email: String!
}

type User {
    id: ID!
    username: String!
    email: String!
}

enum Gender {
    M
    F
    _
}```

2. My GraphQL operations:

I don't know what this is
```graphql
# Put your operations here
  1. My codegen.yml config file:
overwrite: true
schema: "schema.graphql"
documents: 
  - "./document.graphql"
  - "./*.js"
generates:
  generated/graphql.js:
    plugins:
      - "flow"
      - "flow-operations"
  ./graphql.schema.json:
    plugins:
      - "introspection"

Expected behavior I expect it to use ‘_’ or at least ‘’ as property name, instead it is producing the following invalid JS object definition:

export const GenderValues = Object.freeze({
  M: 'M',
  F: 'F',
  : '_'
});

Additional context

Reproduction: https://codesandbox.io/s/enumfailure-l7j7b?file=/document.js

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Urigocommented, Jun 2, 2021

I don’t think there is a real reason cc @dotansimha

0reactions
dotansimhacommented, Jun 20, 2021

By the way, I noticed the namingConvention docs are under certain plug-ins documentation. Is there a reason it is not on the general section?

No real reason, just because the configuration is generated from the plugins code, so it sits next to that.

I merged your PR and the new documentation page should be live in a few minutes. Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using enums | Flow
Learn how to use Flow Enums, including their methods and exhaustive checking. ... like a string , to the enum type (if it...
Read more >
How can I guarantee that my enums definition doesn't change ...
For each entry, create a new local variable whose name starts with ENUM_ or INDEX_ , then the name of the group, then...
Read more >
Generator produces an invalid enum with an underscore "_ ...
Using the 3.14.1 code generator with Java on a MySQL database with an enum field defined as: `t_offset_o` enum('-','+') NOT NULL DEFAULT '+' ......
Read more >
Introducing Flow Enums - Medium
const couldBeStatus: Status | void = Status.cast(someString);. Previously, you would have to create a switch statement with every enum member as ...
Read more >
graphql-code-generator - Bountysource
[flow] enums with underscore produce an invalid object key $ 0. Created 1 year ago in dotansimha/graphql-code-generator with 6 comments. Describe the bug....
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