From b590f0f98f8bcf3ba5bfa48355b068f7598b51e1 Mon Sep 17 00:00:00 2001 From: Ali BARIN Date: Thu, 10 Aug 2023 18:07:24 +0000 Subject: [PATCH] feat: write useConfig hook --- .../web/src/graphql/mutations/update-config.ts | 7 +++++++ packages/web/src/graphql/queries/get-config.ts | 8 ++++++++ packages/web/src/hooks/useConfig.ts | 17 +++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 packages/web/src/graphql/mutations/update-config.ts create mode 100644 packages/web/src/graphql/queries/get-config.ts create mode 100644 packages/web/src/hooks/useConfig.ts diff --git a/packages/web/src/graphql/mutations/update-config.ts b/packages/web/src/graphql/mutations/update-config.ts new file mode 100644 index 00000000..f74e61e3 --- /dev/null +++ b/packages/web/src/graphql/mutations/update-config.ts @@ -0,0 +1,7 @@ +import { gql } from '@apollo/client'; + +export const UPDATE_CONFIG = gql` + mutation UpdateConfig($input: JSONObject) { + updateConfig(input: $input) + } +`; diff --git a/packages/web/src/graphql/queries/get-config.ts b/packages/web/src/graphql/queries/get-config.ts new file mode 100644 index 00000000..6204b5a6 --- /dev/null +++ b/packages/web/src/graphql/queries/get-config.ts @@ -0,0 +1,8 @@ +import { gql } from '@apollo/client'; + +export const GET_CONFIG = gql` + query GetConfig($keys: [String]) { + getConfig(keys: $keys) + } +`; + diff --git a/packages/web/src/hooks/useConfig.ts b/packages/web/src/hooks/useConfig.ts new file mode 100644 index 00000000..eaded736 --- /dev/null +++ b/packages/web/src/hooks/useConfig.ts @@ -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(GET_CONFIG, { variables: { keys } }); + + return { + config: data?.getConfig, + loading, + }; +}