GraphQL Package
The Intuition GraphQL package provides a type-safe interface for interacting with the Intuition API. It serves as the core data fetching layer, offering generated types and React Query hooks for seamless integration with the semantic knowledge graph.
Key Features
- Type-safe GraphQL operations leveraging code gen
- React Query hooks for data fetching
- Reusable GraphQL fragments
- Local-first schema with remote fallback
- Portable package design
Quick Start
Install the package:
pnpm add @0xintuition/graphql
(Optional) Configure the client in your app’s root (
root.tsx
or Next.jslayout.tsx
)
import { configureClient, API_URL_DEV } from '@0xintuition/graphql`
// Configure GraphQL client at module initialization using the URLs from the package. For now, we should use the local URL for development
// This can be updated to use the same environment approach that we use in Portal in the future, or leave up to the template user to configure however makes sense for their use case
configureClient({
apiUrl: API_URL_DEV,
})
- This step is entirely optional. If you omit it the GraphQL package queries and hooks will use the default API URL from the package, which is currently
API_URL_PROD
. API_URL_DEV
andAPI_URL_LOCAL
are both exported from the GraphQL package. You can import these for use withconfigureClient
as shown in the above example.
Schema Management
The package uses a local-first approach for schema management:
- Local
schema.graphql
as source of truth - Remote schema fallback for resilience
- Automatic schema generation during builds
- Version controlled schema for team consistency
Development Workflow
- Code Generation
pnpm codegen:build # Generate types
pnpm codegen:watch # Watch mode for development
- Building
pnpm build # Full build with codegen
pnpm dev # Development mode with watch
- Testing
pnpm test
Package Structure
graphql/
├── src/
│ ├── client.ts # Client configuration
│ ├── fragments/ # Reusable fragments
│ ├── queries/ # GraphQL queries
│ ├── mutations/ # GraphQL mutations
│ └── generated/ # Generated types
├── schema.graphql # Schema definition
└── codegen.ts # Codegen config
Package Approach
- Schema Updates
- Uses the local schema committed in the repository as the priority for the codegen and uses the remote URL as the fallback
- Query Organization
- Uses fragments for reusable fields
- Includes use-case specific queries as well as general purpose queries
- Type Safety
- Leverages generated types from our schema
- Generates React Query hooks as well as document queries that can be used in a server context (or used with another client such as Apollo)
- Client Configuration
- Default client configuration can be overridden in each consumer app
- Supports environment-specific API URLs