Querying Attio data on the client via GraphQL
runQuery
useQuery
npx attio dev
to develop your app, you will be prompted to
Press "o" to open GraphQL Explorer.
. If you do press o
, it will open an
instance of
GraphiQL.
GraphiQL will help you explore the schema as well as autocomplete your query as you type.
null
if there are no errors.Get information about the current user
Get email addresses for the current person record
Get the names and email addresses of people at the current company record
runQuery()
and useQuery()
will accept just a string
as your query, but if you write your
query in a separate file with the .graphql
or .gql
extension, you can then import
your
query into your TypeScript file. If you pass the imported query to these functions, your results
will be strongly typed. The code generator will look for query files as long as you are runnning
npx attio dev
.
Let’s look at an example:
__typename
and the ... on
syntax to match the type of the attribute you are
querying.__typename
before reading the value.
__typename
and then switch
ing on its value.
The record
query takes a record id and an object type and returns the matching object.
Those variables happen to be exactly what the onTrigger()
function on our
record action is given.