Building GraphQL Queries
Learn the fundamentals of constructing GraphQL queries to retrieve specific data from the BuildBetter API.
Building GraphQL Queries
GraphQL queries allow you to specify exactly what data you need, and the response will mirror the structure of your request. Here are some key aspects of building queries:
-
Structure: A basic GraphQL query uses the syntax
query { ... }
(ormutation { ... }
for mutations). Inside, you list the fields you want to retrieve, and you can nest related fields. The response JSON will have the same shape as the fields you asked for. For example, to get a call’s name and start time, you might write:This query asks for the
name
andstarted_at
of the first call (more on theinterview
type below). The result will contain those fields. -
Variables: Instead of hard-coding values in your queries (like IDs or filters), GraphQL variables let you write flexible queries. You define variables in the query signature, and provide their values separately in the request. For example, a query that fetches a specific call by ID using a variable:
In this query,
$callId
is a variable of typebigint!
(an ID type used for calls). Thewhere
filter uses_eq
(equals) to match the call ID. When you send this query, you’d include a JSONvariables
payload such as:{ "callId": 12345 }
. The API will substitute the variable and return the matching call. You can use variables for any dynamic value (IDs, search keywords, filters, etc.), which makes your queries reusable and safer. -
Filtering and Ordering: The API supports rich filtering on query fields. Inside a
where
clause, you can use operators like_eq
(equals),_neq
(not equals),_in
,_ilike
(case-insensitive pattern match), and many others. These correspond to SQL-like filters. For example, to filter documents by status you might usewhere: { status: { _eq: "completed" } }
. You can also sort results using anorder_by
argument on query fields. For example,order_by: { created_at: desc }
will sort results by creation time in descending order. Pagination can be handled with limit/offset arguments – e.g.,limit: 10, offset: 0
to get the first 10 results, then adjust offset for the next page. -
Schema Introspection: The GraphQL schema defines all available types, fields, and operations. You can introspect the schema (for example, using GraphiQL or Apollo Sandbox if provided, or by sending the special
__schema
introspection query) to see the exact fields and types. Key types you’ll be interacting with includeinterview
(calls),extraction
(signals), anddocument
. We’ll explain these in the Data Access section. Each of these types has fields and relationships you can query. For instance, theinterview
type has relationships for participants, transcripts, etc., and thedocument
type has relationships for its creator and any source calls.
In summary, structure your queries to ask for exactly what you need, use variables to parameterize queries, and apply filters to narrow results. In the next section, we’ll look at the specific data models (calls, signals, documents) and how to retrieve their data via GraphQL.