0

I have a graphQL ApolloServer returning a paginated set of Transaction(s) for an Account. Here is a snippet of my schema:

type Account implements Node {
  id: ID!
  name: String!
}
type Transaction implements Node {
  id: ID!
  name: String!
  accountId: ID!
}

The relay spec https://relay.dev/graphql/connections.htm says the field that returns a connection type can take parameters of either: 1) before and last or 2) after and first

This implies they cannot all be optional without defining a default after or before opertation

For a query that handles only the after case, I would make a required after thus:

type Query {
  accounts: [Account]!
  transactions(accountId: ID!,after: String!, first: Int = 10 ): TransactionsBelongToAccountConnection
}

But for one that handles both the before and after case, I would need to make all four of these parameters optional and declare one of after or before modes to be the default:

type Query {
  accounts: [Account]!
  transactions(accountId: ID!, before: Sting, last: Int = 10, after: String, first: Int = 10 ): TransactionsBelongToAccountConnection
}

or (my question is) in graphql is there a way of making exactly one of two parameters required?

NULL pointer
  • 1,116
  • 1
  • 14
  • 27
  • 1
    There is no built-in way of doing that. Your arguments need to be nullable and the logic for requiring one or the other needs to be placed inside your resolver. – Daniel Rearden May 04 '20 at 10:41
  • Thanks Daniel Rearden, this is a duplicate question. I was searching in a context specific to react relay connection, should have just thought of it as a graphql issue. – NULL pointer May 04 '20 at 20:13

0 Answers0