Skip to content
This repository has been archived by the owner on May 26, 2023. It is now read-only.

Nested (optional) input types #144

Closed
Willianvdv opened this issue Oct 11, 2018 · 4 comments
Closed

Nested (optional) input types #144

Willianvdv opened this issue Oct 11, 2018 · 4 comments

Comments

@Willianvdv
Copy link

Willianvdv commented Oct 11, 2018

Given I have a users connection that accepts an input type that accepts a where argument, this where input type has a couple of optional arguments. With GraphQL, you can query like so:

query {
  usersCalledLee: users(where: { firstName: { _eq: "lee" }})
  usersThatAreBots: users(where: { bot: { _eq: true  })
}

In my reason-apollo app, the user can specify these filters and so the where is constructed in my app and passed via the query's variables to the appropriate connection.

module GetUsers = [%graphql
  {|
  query GetUsers($where: WhereInput!){
    reports(first: 100, where: $where }) {
      ...
    }
  }
|}
];

In order to construct the where, I have to specify all the Some and None values so it matches the type.

let where = {
  username: Some({_eq: "lee"})
  bot: None
}

Here's the problematic part, when I use this where as variables for the query, this None will be transformed to nil and send to the GraphQL server. As nil isn't valid input, the server will return a 500.

I'm quite new to the Reason and Apollo game, but I guess the fix for this case would be to use {} rather than nill as None value or remove the entries that have a None value.

What do you think?

@baransu
Copy link
Contributor

baransu commented Oct 11, 2018

That's an issue in graphql_ppx that reason-apollo is using. You can track it here: mhallin/graphql_ppx#59.

@Willianvdv
Copy link
Author

Thanks for your reply @baransu! I'll track that issue.

@Willianvdv
Copy link
Author

@baransu I saw that glennsl/bs-json/issues/50 got resolved, but I have troubles understanding how I can apply this. Can you help me how I can omit the null values from the where I've posted in the example?

@baransu
Copy link
Contributor

baransu commented Oct 22, 2018

The issue still exists in mhallin/graphql_ppx#59. Please check my latest comment. I know how this could be fixed but I'm missing knowledge about OCaml AST generation and how to implement it.

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

No branches or pull requests

2 participants