Preston Garno
Preston Garno

Reputation: 1225

Does a GraphQL Interface definition bind its implementing types to using the same input argument "signature"?

For example, the GitHub API declares a type called Actor:

interface Actor {

    avatarUrl(size: Int): URI!

    login: String!

    resourcePath: URI!

    url: URI!
}
  1. Is it safe to assume that each type which implements Actor takes an Int input argument for the field avatarUrl?
  2. Can a subtype of Actor declare more input arguments on the avatarUrl field?

This is for a transpiler for the schema language (client implementation), so I don't want to make any assumptions which can fail at runtime.

Upvotes: 2

Views: 94

Answers (1)

Daniel Rearden
Daniel Rearden

Reputation: 84877

As far as GraphQL.js is concerned:

  1. Yes, any type that implements the Actor interface will need to include the size argument on its avatarUrl field in the type definition.

    To be clear, if the argument is not-NonNull, a client could still leave it off inside a query. However, it will always need to be included in the type definition or GraphQL will complain.

  2. Yes, the type implementing Actor could declare additional arguments on the field beyond what the Interface mandates. I imagine this would be something of an edge case, as these arguments would not be usable on any queries returning the interface. But a query returning the specific type, not the interface, could technically utilize the additional arguments.

Upvotes: 1

Related Questions