Optional per-request HTTP headers merged over the SDK’s default headers. Because they can scope the response (for example, Authorization), headers is part of the cache key. See Cache Control.
GraphQL record queries return this response structure.
1interface UIAPIQueryResponse{2 uiapi: {3 query: {4[ObjectName: string]: {5 edges?: Array<{6 node?: {7 Id: string;8 // Every field is a { value, displayValue } envelope, not a bare scalar.9 // - value: raw value — use for logic and for writing back to the server10 // - displayValue: locale-formatted string — use for rendering in the UI11[FieldName: string]?: {value?: FieldType | null; displayValue?: string | null} | null;12} | null;13} | null> | null;14} | null;15};16};17}
Subscribe to Query Updates
Query results from graphql.query() are reactive and support real-time updates through subscriptions, which you can use to update your UI automatically when data changes.
The subscribe() method listens for updates to a query result. Subscribers are notified when the data changes due to cache updates or explicit refreshes.
1const result = await dataSdk.graphql?.query<AccountData>({2 query: GET_ACCOUNT,3 variables:{id: accountId},4});56// Subscribe to updates7const unsubscribe = result.subscribe((snapshot)=>{8 console.log("Updated data:", snapshot.data);9 if(snapshot.errors){10 console.warn("Errors:", snapshot.errors);11}12 // Update your UI here13});1415// Clean up when done16unsubscribe();
Refresh Query Data
Use the refresh() method to manually re-fetch data, bypassing the cache.
1const result = await dataSdk.graphql?.query<AccountData>({2 query: GET_ACCOUNT,3 variables:{id: accountId},4});56// Subscribe to updates7result.subscribe((snapshot)=>{8 // UI update logic9 setAccount(snapshot.data);10});1112// Later, refresh the data (e.g., on button click)13async function handleRefresh(){14 await result.refresh(); // Notify subscribers15}
Example: Query Records from a React App
Here’s an example on how to query records. The example uses the useState and useEffect React hooks to manage the component state and respond to data changes.