Skip to content

Commit

Permalink
Merge pull request #81 from onattech/DA-97_getOnePreference
Browse files Browse the repository at this point in the history
DA-97: getOnePreference response updated with preference name
  • Loading branch information
saul-data authored Jan 19, 2022
2 parents 8393f8e + 5eedae4 commit 4a96081
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions frontend/src/graphql/getOnePreference.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
import { gql, GraphQLClient } from "graphql-request";
import { useGlobalAuthState } from "../Auth/UserAuth";
import { gql, GraphQLClient } from 'graphql-request';
import { useGlobalAuthState } from '../Auth/UserAuth';

const graphlqlEndpoint = process.env.REACT_APP_GRAPHQL_ENDPOINT_PRIVATE
const graphlqlEndpoint = process.env.REACT_APP_GRAPHQL_ENDPOINT_PRIVATE;

const GetOnePreference = gql`
query getOnePreference($preference: String!){
getOnePreference(preference: $preference){
value
const query = gql`
query getOnePreference($preference: String!) {
getOnePreference(preference: $preference) {
value
preference
}
}
}
`;

export const useGetOnePreference = () => {
export const useGetOnePreference = () => {
const authState = useGlobalAuthState();
const jwt = authState.authToken.get();

const headers = {
Authorization: "Bearer " + jwt,
Authorization: 'Bearer ' + jwt,
};

const client = new GraphQLClient(graphlqlEndpoint, {
headers,
headers,
});

return async (input) => {
try {
const res = await client.request(GetOnePreference, input);
return res?.getOnePreference;
} catch (error) {
return JSON.parse(JSON.stringify(error, undefined, 2)).response
}
try {
const res = await client.request(query, input);
return res?.getOnePreference;
} catch (error) {
return JSON.parse(JSON.stringify(error, undefined, 2)).response;
}
};
};
};

0 comments on commit 4a96081

Please sign in to comment.