-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from onattech/DA-97_getOnePreference
DA-97: getOnePreference response updated with preference name
- Loading branch information
Showing
1 changed file
with
21 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}; | ||
}; | ||
}; |