GraphQL Endpoints
> One endpoint with a typed schema. Each field that needs logic resolves through its own flow.
A GraphQL endpoint is a route of type GraphQL. Instead of one flow per request, it has a schema: queries, mutations and the types they return. Types come from your Structures and Enums, so the schema stays in sync with the data your flows already use.
| You want | Use | |----------|-----| | One URL per action, plain JSON in and out | REST route | | Clients pick the fields they need, many resources in one request | GraphQL endpoint |
Create an endpoint
1. In the builder or on the API page, click Create Route. 2. Switch Route type to GraphQL. The path defaults to graphql. 3. Click Create. The endpoint opens in the schema editor with an example hello query.
The endpoint answers GET and POST on its path, so it cannot share a path with a GET or POST REST route.
Schema editor
The editor has three views: Schema, SDL and Playground.
| Area | What it holds | |------|---------------| | Query / Mutation | Root fields. Each has a name, a return type, arguments and a resolver. | | Types | Object types from Structures, inline types and enums. Dashed cards are types the schema pulls in on its own, such as input types for arguments. | | Inspector | Edits the selected field or type. With nothing selected it shows the endpoint limits. |
Types from Structures
Click Add type and pick a Structure. Every Structure field becomes a GraphQL field with a matching scalar: string to String, integer to Int, number to Float, boolean to Boolean, object:User to User, enum-value:Role to Role. Array fields become lists.
Uncheck a field under Structure fields to keep it out of the API, for example password_hash. Extra fields add fields that are not in the Structure.
Deploying snapshots the Structures and Enums the schema uses. Editing a Structure later changes the dev schema, not the deployed version, until you deploy again.
Data tables and forms are in the list too, with their columns and form fields as fields: a table named orders appears as OrdersTable, a form named Contact as ContactForm.
Return types
The type picker sets the named type and two flags: [ ] makes it a list, ! makes it non-null. With a list, item! makes the items non-null. [Post!]! is a non-null list of non-null posts.
An argument whose type is an object type takes the matching input type: an argument of type PostInput accepts the data fields of Post.
Resolvers
| Resolver | Behavior | |----------|----------| | Flow | Runs the field's resolver flow. Required for every Query and Mutation field. | | Default | Reads the property with the field's name from the parent value. Fits fields of types returned by another resolver. |
To add a computed field to a type, for example User.posts, select the type and click Add under Resolver fields.
Resolver flows
Click Open resolver flow in the inspector. The flow opens on the regular canvas; Schema in the bar at the top leads back. Every node works in a resolver flow except response nodes.
Resolver Start
| Pin | Direction | Type | |-----|-----------|------| | Execution | Out | sequence | | Parent | Out | object | | Arguments | Out | object | | Context | Out | object | | Info | Out | object |
Parent is the value of the enclosing object, null for Query and Mutation fields. Arguments holds the field arguments by name. Context holds headers, query, method and url of the HTTP request. Info holds fieldName, parentType, returnType, path, operation, operationName and selections (the requested sub-field names).
Resolver Return
| Pin | Direction | Type | |-----|-----------|------| | Execution | In | sequence | | Result | In | any |
Returns the field value. For an object type, return an object whose keys match the field names.
GraphQL Error
| Pin | Direction | Type | |-----|-----------|------| | Execution | In | sequence | | Message | In | string | | Code | In | string | | Extensions | In | object |
Ends the resolver with an error at this field. The field becomes null and the error appears in errors with extensions.code. Other fields of the request still resolve.
To protect an endpoint, put Check API Key in the resolver flows of the fields that need it. The flow sees the request headers, so x-api-key works as on REST routes.
Test in the Playground
Open Playground, write a query and click Run (or press Cmd+Enter). The query goes to the dev version of the endpoint; unsaved changes are saved first. Example writes a query for the first Query field.
query {
user(id: "42") {
email
posts { title }
}
}
Call the endpoint
curl https://app.brickr.dev/my-workspace-id/shop/graphql \
-H "Content-Type: application/json" \
-d '{"query":"query($id: ID!) { user(id: $id) { email } }","variables":{"id":"42"}}'
GET requests take query, variables (JSON) and operationName as URL parameters and only run queries. Mutations need POST.
The response follows the GraphQL spec: data with the requested fields, plus errors when a field failed.
Limits and introspection
Select nothing in the schema editor to edit the endpoint limits.
| Setting | Default | Effect | |---------|---------|--------| | Max query depth | 10 | Rejects deeper queries before any resolver runs. | | Max fields per request | 250 | Rejects queries that select more fields. | | Max resolver flow runs per request | 250 | Stops resolving after this many flow runs. | | Allow introspection | On | Lets tools such as GraphiQL read the schema. |
Billing
The GraphQL request counts as one request. Each resolver flow run counts as one more request and is logged as a subrequest of it. A query for 10 users with a flow-resolved posts field counts 1 + 1 + 10 = 12 requests; fields with the default resolver are free.
Execution runtimes
Resolver flows run on the same runtimes as REST routes. With the experimental Go runtime selected, each resolver flow runs in Go and hands nodes Go does not support back to TypeScript.
Versioning
Save and deploy work as for REST routes. Deploy validates the schema and every resolver flow a field uses and compiles them. Errors show in the console, for example Query.user: resolver flow "query_user" does not exist. Opening a deployed version shows the schema read only.