Set up a GQL client package (#19)

* Set up GQL client package

* Add client method to get user

---------

Co-authored-by: neeraj <neeraj.rtly@gmail.com>
This commit is contained in:
prathamesh0
2024-02-01 11:37:57 +05:30
committed by Ashwin Phatak
co-authored by neeraj
parent e4c099f8c3
commit dc88b2c301
10 changed files with 449 additions and 10 deletions
+26
View File
@@ -0,0 +1,26 @@
import { ApolloClient, InMemoryCache, NormalizedCacheObject } from '@apollo/client';
import { getUser } from './gql-queries';
export interface GraphQLConfig {
gqlEndpoint: string;
}
export class GQLClient {
private client: ApolloClient<NormalizedCacheObject>;
constructor (config: GraphQLConfig) {
this.client = new ApolloClient({
uri: config.gqlEndpoint,
cache: new InMemoryCache()
});
}
async getUser () : Promise<any> {
const { data } = await this.client.query({
query: getUser
});
return data;
}
}
+13
View File
@@ -0,0 +1,13 @@
import { gql } from '@apollo/client';
export const getUser = gql`
query {
user {
id
name
email
createdAt
updatedAt
}
}
`;