Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to support optional response keys #6

Open
bstanley0811 opened this issue Apr 20, 2020 · 0 comments
Open

How to support optional response keys #6

bstanley0811 opened this issue Apr 20, 2020 · 0 comments

Comments

@bstanley0811
Copy link

Basically what the title states, but here's a bit more context and an example:

I have a response object that has some optional keys depending if data for the parent item exists. However, it seems that these fields can never be null as protoc-gen-twirpql is generating a graphQL schema file with these optional fields marked with a !.

Detailed context: I have an array of objects I'm pulling from one db table and then OUTER JOINING those objects to another table and it's very likely that some of the fields will be null. If they are null, I would like to not append keys to the parent object. See the example response body, I'm looking for.

# desired response body
data: {
  screens: [
    {
      id: 1,
      name: "Screen One"
    },
    {
      id: 2,
      name: "Screen Two",
      position: {
        x: 112,
        y: 53
      }
    }
  ]
}

In the desired response, you can see that screen 1 doesn't have corresponding coordinate data, so position is not there, while screen 2 does have coordinate data. But because the generated schema file is putting a ! on the position field, GraphQL is throwing a must not be null error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant