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] Too restrictive type on optional fields in mutation responses

See original GitHub issue

Describe the bug Consider following schema:

schema {
  mutation: Mutation
}

type MutationResponse {
  success: Boolean
  errors: [String!]
}
  
type Mutation {
  update(id: ID!): MutationResponse
}

and obviously config

generates:
  demo.js:
    - flow

generated type will be

export type MutationResponse = {
  success: ?boolean
  errors: ?Array<string>
}

which means I always need to return success and errors field even if they are null/undefined. All known graphql server implementations tolerate that, so I believe it should be:

export type MutationResponse = {
  success?: ?boolean
  errors?: ?Array<string>
}

which allows not to have field in response.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
xanfcommented, Jan 12, 2019

@adelsz sorry, you’re perfectly right. Let’s say: foo?: ?string sounds better and matches spec

0reactions
dotansimhacommented, Jan 20, 2019

Fixed in 0.16.0. Thanks @xanf

Read more comments on GitHub >

github_iconTop Results From Across the Web

Designing GraphQL Mutations
This is useful for schemas where you want to order the mutations alphabetically (the Ruby GraphQL gem always orders fields alphabetically) and ...
Read more >
GraphQL API style guide - GitLab Docs
Non-nullable fields should only be used when a field is required, very unlikely to become optional in the future, and very easy to...
Read more >
Code Smells: Mutation | The IntelliJ IDEA Blog
This is part of a series investigating code that looks suspicious (“code smells”), and exploring possible alternatives.
Read more >
A mutation-based gene set predicts survival benefit after ...
In this study, we established a comprehensive mutation-based gene set across different tumor types to predict the efficacy of ICI therapy.
Read more >
Api graphql styleguide · Development · Help · GitLab
Non-nullable fields should only be used when a field is required, very unlikely to become optional in the future, and very easy to...
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