"The fields by which you are allowed to sort any query that returns an `RoleConnection`"
enum RoleSortByField {
  "Role ID"
  _id

  "Role name"
  name
}

"Represents a named role"
type Role implements Node {
  "The role ID"
  _id: ID!

  "A unique name for the role"
  name: String!
}

"""
Wraps a list of `Roles`, providing pagination cursors and information.

For information about what Relay-compatible connections are and how to use them, see the following articles:
- [Relay Connection Documentation](https://facebook.github.io/relay/docs/en/graphql-server-specification.html#connections)
- [Relay Connection Specification](https://facebook.github.io/relay/graphql/connections.htm)
- [Using Relay-style Connections With Apollo Client](https://www.apollographql.com/docs/react/recipes/pagination.html)
"""
type RoleConnection {
  "The list of nodes that match the query, wrapped in an edge to provide a cursor string for each"
  edges: [RoleEdge]

  """
  You can request the `nodes` directly to avoid the extra wrapping that `NodeEdge` has,
  if you know you will not need to paginate the results.
  """
  nodes: [Role]

  "Information to help a client request the next or previous page"
  pageInfo: PageInfo!

  "The total number of nodes that match your query"
  totalCount: Int!
}

"A connection edge in which each node is a `Role` object"
type RoleEdge implements NodeEdge {
  "The cursor that represents this node in the paginated results"
  cursor: ConnectionCursor!

  "The role"
  node: Role
}

extend type Shop {
  "Returns a list of roles for this shop, as a Relay-compatible connection."
  roles(
    "Return only results that come after this cursor. Use this with `first` to specify the number of results to return."
    after: ConnectionCursor,

    "Return only results that come before this cursor. Use this with `last` to specify the number of results to return."
    before: ConnectionCursor,

    "Return at most this many results. This parameter may be used with either `after` or `offset` parameters."
    first: ConnectionLimitInt,

    "Return at most this many results. This parameter may be used with the `before` parameter."
    last: ConnectionLimitInt,

    "Return only results that come after the Nth result. This parameter may be used with the `first` parameter."
    offset: Int,

    "Return results sorted in this order"
    sortOrder: SortOrder = asc,

    "By default, roles are sorted alphabetically by name. Set this to sort by one of the other allowed fields"
    sortBy: RoleSortByField = name
  ): RoleConnection
}

extend type Query {
  "Returns a paged list of all roles associated with a shop"
  roles(
    "Return valid roles for this shop"
    shopId: ID!,

    "Return only results that come after this cursor. Use this with `first` to specify the number of results to return."
    after: ConnectionCursor,

    "Return only results that come before this cursor. Use this with `last` to specify the number of results to return."
    before: ConnectionCursor,

    "Return at most this many results. This parameter may be used with either `after` or `offset` parameters."
    first: ConnectionLimitInt,

    "Return at most this many results. This parameter may be used with the `before` parameter."
    last: ConnectionLimitInt,

    "Return only results that come after the Nth result. This parameter may be used with the `first` parameter."
    offset: Int,

    "Return results sorted in this order"
    sortOrder: SortOrder = asc,

    "By default, roles are sorted alphabetically by name. Set this to sort by one of the other allowed fields"
    sortBy: RoleSortByField = name
  ): RoleConnection
}
