The schema for a Reindex app is defined in JSON. You can fetch the schema for your app using a CLI command:
reindex schema-fetch
By default this saves the schema to a file named ReindexSchema.json.
After editing the schema in your favorite editor, push it to your app with:
reindex schema-push
Reindex automatically migrates the database of the app to the new schema and generates things like mutations and input objects for it automatically.
You can also do migrations programmatically using migrate mutation.
Tip: Documentation browser
After pushing the schema to your app, you can view the whole GraphQL schema, including also the builtin types and auto-generated fields, in the documentation browser of GraphiQL.
Open GraphiQL with
reindex graphiqland click “Docs” in the top right corner.
The schema file includes an array of types for the schema. For example:
[
{
"kind": "OBJECT",
"name": "User",
"interfaces": [
"Node"
],
"fields": [
{
"name": "id",
"type": "ID",
"nonNull": true,
"unique": true
}
]
}
]
The properties supported in the schema definition are documented below.
The type object defines a single type in the schema.
fields: [ReindexField] Array of field objects that describe the fields of the type.
permissions: [ReindexPermission] Array of permissions that determine who has rights to read and change the nodes of this type.
interfaces: [String] Array with the names of interfaces the type implements.
Supported interfaces are:
Node: Defines a type with globally unique ID.Node types
The node types can be fetched using the
noderoot field or the automatically created type specific root fields (e.g.todoById). They are also accessible through the connection of all nodes of a type (e.g.{ viewer { allTodos { ... } } }).They can also be referenced in other node types, forming relationships between types.
The node types also get a set of mutations created for them automatically. Here’s a list of mutations for type
Todo:
createTodo– Creates a newTodoobject.updateTodo– Updates the givenTodoobject. The given fields are merged to the existing object.replaceTodo– Replaces the givenTodoobject.deleteTodo– Deletes the givenTodoobject.
kind: String! The kind of the type. At the moment "OBJECT" is the only supported value.
name: String! The name of the type.
The name must start with a capital letter. Allowed characters are letters A-Z, a-z and underscore (_). Type names that start with “Reindex” are reserved for builtin types.
pluralName: String An optional pluralized name for the type. If not specified, the default English
pluralization will be used for generated field names like allStories.
defaultOrdering: ReindexOrdering For fields of type Connection, defines the default sorting order for the items
in the connection. If specified, must be an object with properties field
(name of a field) and order (either “ASC” or “DESC”).
deprecationReason: String If given, makes the field show as deprecated.
description: String An optional description for the GraphQL field. The description is shown in the documentation of your app’s API and also when you’re typing a query in GraphiQL.
name: String! The name of the field. Allowed characters are letters A-Z, a-z and underscore (_).
nonNull: Boolean Sets the GraphQL field as non-null.
unique: Boolean Makes Reindex enforce uniqueness for this field. In addition, for each unique field a root field will be created for fetching this field.
ofType: String The inner type of the field, required for Connection and List fields. For
example:
{ "name": "myList", "type": "List", "ofType": "String" }
User nodes:{ "name": "myUsers", "type": "Connection", "ofType": "User" }
orderable: Boolean If set, orderBy can be used on this field. Can be only set on scalar fields.
filterable: Boolean If set, connection filter argument will be generated for this field. Can only be set on scalar fields.
reverseName: String The name of the related field in the referenced type, required for object fields with a node type and for the corresponding Connection fields.
type: String! Type of the field.
Following types are supported.
BooleanDateTimeFloatID (only valid as the id field for nodes)IntStringList – A list of scalars or non-node objects. ofType defines the type of
list elements.Connection – A paginated list of nodes. Used to define one-to-many or
many-to-many relationships between node types. ofType defines the type of
connected nodes. A connection field always has a corresponding reverse field
in the other type and the name of that field is defined with reverseName.
type of the reverse field is a node object type.type of the reverse field is also Connection.Node interface, the field creates a
connection between the types. The field must have a related Connection
field in the other type.Here’s a larger example of a schema for an app that stores movies and TV shows fetched from The Movie Database (TMDb):
[
{
"name": "TvSeason",
"kind": "OBJECT",
"interfaces": [
"Node"
],
"fields": [
{
"name": "air_date",
"type": "DateTime"
},
{
"name": "episodes",
"type": "Connection",
"ofType": "TvEpisode",
"reverseName": "season"
},
{
"name": "id",
"type": "ID",
"nonNull": true,
"unique": true
},
{
"name": "name",
"type": "String"
},
{
"name": "overview",
"type": "String"
},
{
"name": "poster_path",
"type": "String"
},
{
"name": "season_number",
"type": "Int"
},
{
"name": "series",
"type": "TvSeries",
"reverseName": "seasons"
}
]
},
{
"name": "Person",
"kind": "OBJECT",
"interfaces": [
"Node"
],
"fields": [
{
"name": "adult",
"type": "Boolean"
},
{
"name": "also_known_as",
"type": "List",
"ofType": "String"
},
{
"name": "biography",
"type": "String"
},
{
"name": "birthday",
"type": "DateTime"
},
{
"name": "credits",
"type": "Connection",
"ofType": "Credit",
"reverseName": "person"
},
{
"name": "deathday",
"type": "DateTime"
},
{
"name": "homepage",
"type": "String"
},
{
"name": "id",
"type": "ID",
"nonNull": true,
"unique": true
},
{
"name": "imdb_id",
"type": "String"
},
{
"name": "name",
"type": "String"
},
{
"name": "place_of_birth",
"type": "String"
},
{
"name": "popularity",
"type": "Float"
},
{
"name": "profile_path",
"type": "String"
}
]
},
{
"name": "TvEpisode",
"kind": "OBJECT",
"interfaces": [
"Node"
],
"fields": [
{
"name": "air_date",
"type": "DateTime"
},
{
"name": "episode_number",
"type": "Int"
},
{
"name": "id",
"type": "ID",
"nonNull": true,
"unique": true
},
{
"name": "name",
"type": "String"
},
{
"name": "overview",
"type": "String"
},
{
"name": "production_code",
"type": "String"
},
{
"name": "season",
"type": "TvSeason",
"reverseName": "episodes"
},
{
"name": "season_number",
"type": "Int"
},
{
"name": "still_path",
"type": "String"
},
{
"name": "vote_average",
"type": "Float"
},
{
"name": "vote_count",
"type": "Int"
}
]
},
{
"name": "Country",
"kind": "OBJECT",
"interfaces": [],
"fields": [
{
"name": "iso_3166_1",
"type": "String"
},
{
"name": "name",
"type": "String"
}
]
},
{
"name": "Genre",
"kind": "OBJECT",
"interfaces": [],
"fields": [
{
"name": "id",
"type": "String"
},
{
"name": "name",
"type": "String"
}
]
},
{
"name": "Creator",
"kind": "OBJECT",
"interfaces": [],
"fields": [
{
"name": "id",
"type": "String"
},
{
"name": "name",
"type": "String"
},
{
"name": "profile_path",
"type": "String"
}
]
},
{
"name": "Movie",
"kind": "OBJECT",
"interfaces": [
"Node"
],
"fields": [
{
"name": "adult",
"type": "Boolean"
},
{
"name": "backdrop_path",
"type": "String"
},
{
"name": "belongs_to_collection",
"type": "Collection"
},
{
"name": "budget",
"type": "Int"
},
{
"name": "credits",
"type": "Connection",
"ofType": "Credit",
"reverseName": "movie"
},
{
"name": "genres",
"type": "List",
"ofType": "Genre"
},
{
"name": "homepage",
"type": "String"
},
{
"name": "id",
"type": "ID",
"nonNull": true,
"unique": true
},
{
"name": "imdb_id",
"type": "String"
},
{
"name": "original_language",
"type": "String"
},
{
"name": "original_title",
"type": "String"
},
{
"name": "overview",
"type": "String"
},
{
"name": "popularity",
"type": "Float"
},
{
"name": "poster_path",
"type": "String"
},
{
"name": "production_companies",
"type": "List",
"ofType": "Company"
},
{
"name": "production_countries",
"type": "List",
"ofType": "Country"
},
{
"name": "release_date",
"type": "DateTime"
},
{
"name": "revenue",
"type": "Int"
},
{
"name": "runtime",
"type": "Int"
},
{
"name": "spoken_languages",
"type": "List",
"ofType": "Language"
},
{
"name": "status",
"type": "String"
},
{
"name": "tagline",
"type": "String"
},
{
"name": "title",
"type": "String"
},
{
"name": "video",
"type": "Boolean"
},
{
"name": "vote_average",
"type": "Float"
},
{
"name": "vote_count",
"type": "Int"
}
]
},
{
"name": "Language",
"kind": "OBJECT",
"interfaces": [],
"fields": [
{
"name": "iso_639_1",
"type": "String"
},
{
"name": "name",
"type": "String"
}
]
},
{
"name": "User",
"kind": "OBJECT",
"interfaces": [
"Node"
],
"fields": [
{
"name": "id",
"type": "ID",
"nonNull": true,
"unique": true
}
]
},
{
"name": "TvSeries",
"kind": "OBJECT",
"interfaces": [
"Node"
],
"fields": [
{
"name": "backdrop_path",
"type": "String",
"description": "File path for the backdrop image URL."
},
{
"name": "created_by",
"type": "List",
"description": "A list of creators of the TV series.",
"ofType": "Creator"
},
{
"name": "credits",
"type": "Connection",
"description": "All the cast and crew credits for the TV series.",
"ofType": "Credit",
"reverseName": "series"
},
{
"name": "episode_run_time",
"type": "List",
"description": "A list of all episode run times (in minutes)",
"ofType": "Int"
},
{
"name": "first_air_date",
"type": "DateTime"
},
{
"name": "genres",
"type": "List",
"ofType": "Genre"
},
{
"name": "homepage",
"type": "String"
},
{
"name": "id",
"type": "ID",
"nonNull": true,
"unique": true
},
{
"name": "in_production",
"type": "Boolean"
},
{
"name": "languages",
"type": "List",
"ofType": "String"
},
{
"name": "last_air_date",
"type": "DateTime"
},
{
"name": "name",
"type": "String"
},
{
"name": "networks",
"type": "List",
"ofType": "TvNetwork"
},
{
"name": "number_of_episodes",
"type": "Int"
},
{
"name": "number_of_seasons",
"type": "Int"
},
{
"name": "origin_country",
"type": "List",
"ofType": "String"
},
{
"name": "original_language",
"type": "String"
},
{
"name": "original_name",
"type": "String"
},
{
"name": "overview",
"type": "String"
},
{
"name": "popularity",
"type": "Float",
"description": "A number representing the relative popularity of the TV series."
},
{
"name": "poster_path",
"type": "String"
},
{
"name": "production_companies",
"type": "List",
"ofType": "Company"
},
{
"name": "seasons",
"type": "Connection",
"description": "A connection to all the seasons of this TV series.",
"ofType": "TvSeason",
"reverseName": "series"
},
{
"name": "status",
"type": "String"
},
{
"name": "type",
"type": "String"
},
{
"name": "vote_average",
"type": "Float",
"description": "Average rating of this TV series. (0-10)"
},
{
"name": "vote_count",
"type": "Int"
}
]
},
{
"name": "Collection",
"kind": "OBJECT",
"interfaces": [],
"fields": [
{
"name": "backdrop_path",
"type": "String"
},
{
"name": "id",
"type": "String"
},
{
"name": "name",
"type": "String"
},
{
"name": "poster_path",
"type": "String"
}
]
},
{
"name": "Credit",
"kind": "OBJECT",
"interfaces": [
"Node"
],
"fields": [
{
"name": "character",
"type": "String",
"description": "Name of a character. Included in cast credits."
},
{
"name": "credit_type",
"type": "String",
"description": "Credit type. Possible values are \"cast\" and \"crew\"."
},
{
"name": "department",
"type": "String"
},
{
"name": "id",
"type": "ID",
"nonNull": true,
"unique": true
},
{
"name": "job",
"type": "String",
"description": "Job title. Included in crew credits."
},
{
"name": "media_type",
"type": "String",
"description": "Media type of this Credit. (`tv` or `movie`)."
},
{
"name": "movie",
"type": "Movie",
"description": "For movie credits, includes the movie of this Credit.",
"reverseName": "credits"
},
{
"name": "name",
"type": "String",
"description": "Name of the person this Credit belongs to."
},
{
"name": "order",
"type": "Int",
"description": "A sequence number for default ordering of credits"
},
{
"name": "person",
"type": "Person",
"description": "The person this Credit belongs to.",
"reverseName": "credits"
},
{
"name": "profile_path",
"type": "String",
"description": "The file path for the profile image URL."
},
{
"name": "series",
"type": "TvSeries",
"description": "For TV credits, includes the TV series of this Credit.",
"reverseName": "credits"
}
]
},
{
"name": "TvNetwork",
"kind": "OBJECT",
"interfaces": [],
"fields": [
{
"name": "id",
"type": "String"
},
{
"name": "name",
"type": "String"
}
]
},
{
"name": "Company",
"kind": "OBJECT",
"interfaces": [],
"fields": [
{
"name": "id",
"type": "String"
},
{
"name": "name",
"type": "String"
}
]
}
]