Simple page de modification de profil

This commit is contained in:
2020-07-16 20:21:58 +02:00
parent 05dd505d6b
commit 758c166f27
14 changed files with 284 additions and 29 deletions

View File

@ -1,10 +1,11 @@
import ApolloClient from 'apollo-client';
import ApolloClient, { DefaultOptions } from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { split } from 'apollo-link';
import { HttpLink } from 'apollo-link-http';
import { WebSocketLink } from 'apollo-link-ws';
import { getMainDefinition } from 'apollo-utilities';
import { getMainDefinition, variablesInOperation } from 'apollo-utilities';
import gql from 'graphql-tag';
import { ProfileChanges } from '../store/actions/profile';
export class UnauthorizedError extends Error {
constructor(...args: any[]) {
@ -54,10 +55,22 @@ export class DaddyClient {
wsLink,
httpLink,
);
const defaultOptions: DefaultOptions = {
watchQuery: {
fetchPolicy: 'no-cache',
errorPolicy: 'ignore',
},
query: {
fetchPolicy: 'no-cache',
errorPolicy: 'all',
},
};
this.gql = new ApolloClient<any>({
link: link,
cache: new InMemoryCache(),
defaultOptions,
});
}
@ -66,6 +79,7 @@ export class DaddyClient {
query: gql`
query {
userProfile {
name,
email,
createdAt,
connectedAt
@ -75,6 +89,24 @@ export class DaddyClient {
.then(this.assertAuthorization)
}
updateProfile(changes: ProfileChanges) {
return this.gql.mutate({
variables: {
changes,
},
mutation: gql`
mutation updateProfile($changes: ProfileChanges!) {
updateProfile(changes: $changes) {
name,
email,
createdAt,
connectedAt
}
}`,
})
.then(this.assertAuthorization)
}
assertAuthorization({ status, data }: any) {
if (status === 401) return Promise.reject(new UnauthorizedError());
return data;