feat: write useConfig hook
This commit is contained in:
7
packages/web/src/graphql/mutations/update-config.ts
Normal file
7
packages/web/src/graphql/mutations/update-config.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import { gql } from '@apollo/client';
|
||||||
|
|
||||||
|
export const UPDATE_CONFIG = gql`
|
||||||
|
mutation UpdateConfig($input: JSONObject) {
|
||||||
|
updateConfig(input: $input)
|
||||||
|
}
|
||||||
|
`;
|
8
packages/web/src/graphql/queries/get-config.ts
Normal file
8
packages/web/src/graphql/queries/get-config.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import { gql } from '@apollo/client';
|
||||||
|
|
||||||
|
export const GET_CONFIG = gql`
|
||||||
|
query GetConfig($keys: [String]) {
|
||||||
|
getConfig(keys: $keys)
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
17
packages/web/src/hooks/useConfig.ts
Normal file
17
packages/web/src/hooks/useConfig.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import { useQuery } from '@apollo/client';
|
||||||
|
import { IJSONObject } from '@automatisch/types';
|
||||||
|
|
||||||
|
import { GET_CONFIG } from 'graphql/queries/get-config';
|
||||||
|
|
||||||
|
type QueryResponse = {
|
||||||
|
getConfig: IJSONObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function useConfig(keys?: string[]) {
|
||||||
|
const { data, loading } = useQuery<QueryResponse>(GET_CONFIG, { variables: { keys } });
|
||||||
|
|
||||||
|
return {
|
||||||
|
config: data?.getConfig,
|
||||||
|
loading,
|
||||||
|
};
|
||||||
|
}
|
Reference in New Issue
Block a user