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

Nested (optional) input types #144

@Willianvdv

Description

@Willianvdv

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions