graphql-request (simplest)
npm install graphql-request graphql
import { GraphQLClient, gql } from "graphql-request";
const client = new GraphQLClient("https://app.betacit.com/graphql", {
headers: { Authorization: `Bearer ${process.env.TACIT_API_KEY}` },
});
const data = await client.request(gql`
{
building(siteId: "your-site-id") {
id
name
equipment(is: "AHU") {
name
points(is: "Temperature_Sensor") {
name
unit
currentValue { value timestamp quality }
}
}
}
}
`);
Apollo Client
npm install @apollo/client graphql
import { ApolloClient, InMemoryCache, gql } from "@apollo/client";
const client = new ApolloClient({
uri: "https://app.betacit.com/graphql",
cache: new InMemoryCache(),
headers: { Authorization: `Bearer ${process.env.TACIT_API_KEY}` },
});
const { data } = await client.query({
query: gql`
{
building(siteId: "your-site-id") { id name }
}
`,
});
Codegen
Generate TypeScript types from the Tacit GraphQL schema:npm install -D @graphql-codegen/cli @graphql-codegen/typescript
codegen.yml
schema: "https://app.betacit.com/graphql"
generates:
./src/generated/types.ts:
plugins:
- typescript
- typescript-operations
npx graphql-codegen
