The OnSign GraphQL API represents an architectural and conceptual shift from a regular REST API. You will likely encounter some new terminology in the these guides, so take a look below before diving in.
A schema defines a GraphQL API's type system. It describes the complete set of possible data (objects, fields, relationships, everything) that a client can access. Calls from the client are validated and executed against the schema. A client can find information about the schema via introspection. A schema resides on the GraphQL API server. For more information, see Discovering the GraphQL API.
Scalars are primitive values like Int
, Float
, String
, Boolean
, or ID
.
Unlike fields, scalar cannot have nested values.
A field is a unit of data you can retrieve from an object.
The official GraphQL spec says this about fields:
The GraphQL query language is basically about selecting fields on objects. All GraphQL operations must specify their selections down to fields which return scalar values to ensure an unambiguously shaped response.
This means that if you try to return a field that is not a scalar, schema validation will throw an error. You must add nested subfields until all fields return scalars.
An argument is a set of key-value pairs attached to a specific field. Some fields require an argument. Mutations require an input object as an argument.
A GraphQL schema may use the term implements to define how an object inherits from an interface.
Here's a contrived example of a schema that defines interface X and object Y:
interface X {
some_field: String!
other_field: String!
}
type Y implements X {
some_field: String!
other_field: String!
new_field: String!
}
This means object Y requires the same fields/arguments/return types that interface X does, while adding new fields specific to object Y.
(The !
means the field is required.)
In the reference docs, you'll find that:
Connections let you query related objects as part of the same call. With connections, you can use a single GraphQL call to fetch multiple, different resources.
It's helpful to picture a graph: dots connected by lines. The dots are nodes, the lines are edges. A connection defines a relationship between nodes.
Edges represent connections between nodes. When you query a connection, you traverse its edges to get to its nodes. Every edges field has a node field and a cursor field. Cursors are used for pagination.
Node is a generic term for an object. You can look up a node directly, or you can access related nodes via a connection. If you specify a node that does not return a scalar, you must include subfields until all fields return scalars.
GraphQL is introspective. This means you can query a GraphQL schema for details about itself.
__schema
to list all types defined in the schema and get details about each:
query {
__schema {
types {
name
kind
description
fields {
name
}
name
}
}
}
__type
to get details about any type:
query {
__type(name: "Organization") {
name
kind
description
fields {
name
}
}
}
You can also run an introspection query of the schema via a GET
request:
curl https://api.onsign.tv/graphql -H 'Content-Type: application/json' -H 'Authorization: token YOUR-TOKEN'
The results are in JSON, so we recommend pretty-printing them for easier reading and searching.
You can use a command-line tool like jq
or pipe the results into python -m json.tool
for this purpose.
Note:
The introspection query is probably the only GET
request you'll run in GraphQL.
If you're passing a body, the GraphQL request method is POST
, whether it's a query or a mutation.
For more information about performing queries, see "Forming calls with GraphQL."