Remplacement de Redux/Saga par Apollo
This commit is contained in:
21
client/src/gql/client.tsx
Normal file
21
client/src/gql/client.tsx
Normal file
@ -0,0 +1,21 @@
|
||||
import { ApolloClient, InMemoryCache, HttpLink } from '@apollo/client';
|
||||
import { Config } from '../config';
|
||||
import { WebSocketLink } from "@apollo/client/link/ws";
|
||||
import { RetryLink } from "@apollo/client/link/retry";
|
||||
import { SubscriptionClient } from "subscriptions-transport-ws";
|
||||
|
||||
|
||||
const subscriptionClient = new SubscriptionClient(Config.subscriptionEndpoint, {
|
||||
reconnect: true
|
||||
});
|
||||
|
||||
const link = new RetryLink().split(
|
||||
(operation) => operation.operationName === 'subscription',
|
||||
new WebSocketLink(subscriptionClient),
|
||||
new HttpLink({ uri: Config.graphQLEndpoint, credentials: 'include' })
|
||||
);
|
||||
|
||||
export const client = new ApolloClient<any>({
|
||||
cache: new InMemoryCache(),
|
||||
link: link,
|
||||
});
|
15
client/src/gql/mutations/profile.tsx
Normal file
15
client/src/gql/mutations/profile.tsx
Normal file
@ -0,0 +1,15 @@
|
||||
import { gql, useQuery, useMutation } from '@apollo/client';
|
||||
|
||||
const MUTATION_UPDATE_USER_PROFILE = gql`
|
||||
mutation updateUserProfile($changes: ProfileChanges!) {
|
||||
updateProfile(changes: $changes) {
|
||||
id,
|
||||
name,
|
||||
createdAt,
|
||||
connectedAt,
|
||||
}
|
||||
}`;
|
||||
|
||||
export function useUpdateUserProfileMutation() {
|
||||
return useMutation(MUTATION_UPDATE_USER_PROFILE);
|
||||
}
|
16
client/src/gql/queries/profile.tsx
Normal file
16
client/src/gql/queries/profile.tsx
Normal file
@ -0,0 +1,16 @@
|
||||
import { gql, useQuery } from '@apollo/client';
|
||||
|
||||
const QUERY_USER_PROFILE = gql`
|
||||
query userProfile {
|
||||
userProfile {
|
||||
id,
|
||||
name,
|
||||
email,
|
||||
createdAt,
|
||||
connectedAt
|
||||
}
|
||||
}`;
|
||||
|
||||
export function useUserProfileQuery() {
|
||||
return useQuery(QUERY_USER_PROFILE, { fetchPolicy: "network-only" });
|
||||
}
|
20
client/src/gql/queries/workgroups.tsx
Normal file
20
client/src/gql/queries/workgroups.tsx
Normal file
@ -0,0 +1,20 @@
|
||||
import { gql, useQuery } from '@apollo/client';
|
||||
|
||||
const QUERY_WORKGROUP = gql`
|
||||
query workgroups {
|
||||
workgroups {
|
||||
id,
|
||||
name,
|
||||
createdAt,
|
||||
closedAt,
|
||||
members {
|
||||
id,
|
||||
email
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export function useWorkgroupsQuery(options = {}) {
|
||||
return useQuery(QUERY_WORKGROUP, options);
|
||||
}
|
Reference in New Issue
Block a user