forked from cerc-io/snowballtools-base
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:
committed by
Ashwin Phatak
co-authored by
neeraj
parent
e4c099f8c3
commit
dc88b2c301
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { gql } from '@apollo/client';
|
||||
|
||||
export const getUser = gql`
|
||||
query {
|
||||
user {
|
||||
id
|
||||
name
|
||||
email
|
||||
createdAt
|
||||
updatedAt
|
||||
}
|
||||
}
|
||||
`;
|
||||
Reference in New Issue
Block a user