0.0.0-alpha.4 • Published 5 months ago
@aichatkit/apollo-adapter v0.0.0-alpha.4
@aichatkit/apollo-adapter
Apollo GraphQL implementation of the network adapter for Hypermode ChatKit.
Installation
npm install @aichatkit/apollo-adapter @apollo/client graphqlUsage
import { ApolloAdapter } from '@aichatkit/apollo-adapter';
import { ChatInterface } from '@aichatkit/ui';
import { ApolloClient, InMemoryCache } from '@apollo/client';
// Option 1: Create with configuration options
const networkAdapter = new ApolloAdapter({
apiUrl: 'http://localhost:8686/graphql',
apiToken: 'your-auth-token',
maxRetries: 3
});
// Option 2: Create with existing Apollo Client
const client = new ApolloClient({
uri: 'http://localhost:8686/graphql',
cache: new InMemoryCache()
});
const networkAdapter = new ApolloAdapter({
apolloClient: client
});
// Use with ChatInterface
function ChatApp() {
return (
<ChatInterface
networkAdapter={networkAdapter}
// other props...
/>
);
}Configuration Options
The ApolloAdapter constructor accepts an optional configuration object with the following properties:
apiUrl: The GraphQL API URL (default: 'http://localhost:8686/graphql')apiToken: Authentication token for the APImaxRetries: Maximum number of retry attempts for failed requests (default: 3)apolloClient: Custom Apollo Client instance (if provided, other options will be ignored)chatQuery: Custom GraphQL query for chat (must contain variables: $query and $chatHistory)
API
In addition to implementing all methods from the base NetworkAdapter, this adapter provides:
getClient(): ApolloClient<NormalizedCacheObject>: Returns the underlying Apollo Client instance
Default GraphQL Query
The adapter uses the following default GraphQL query:
query Chat($query: String!, $chatHistory: String!) {
chat(query: $query, chat_history: $chatHistory) {
message
history
}
}You can customize this by providing a different query in the configuration.
License
MIT © Hypermode
0.0.0-alpha.4
5 months ago
0.0.0-alpha.3
5 months ago
0.0.0-alpha.2
5 months ago
0.0.0-alpha.1
5 months ago
0.0.0-alpha.0
5 months ago