From 320f15417aded2051b4ff04ece808feba333633e Mon Sep 17 00:00:00 2001 From: Aaron Croissette Date: Sat, 17 Oct 2020 15:27:37 -0400 Subject: [PATCH 1/3] Support for multi-store M2 backends Add configuration option for GraphQL "Store" parameter --- src/config.ts | 1 + src/fetchWithGraphQl.ts | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/config.ts b/src/config.ts index 3ad1f45..e47f78d 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,2 +1,3 @@ export const host = process.env.M2_CONFIG_HOST; export const graphQlHost = `${host}/graphql`; +export const store = process.env.M2_CONFIG_STORE; \ No newline at end of file diff --git a/src/fetchWithGraphQl.ts b/src/fetchWithGraphQl.ts index 711d996..cfc51ac 100644 --- a/src/fetchWithGraphQl.ts +++ b/src/fetchWithGraphQl.ts @@ -1,5 +1,5 @@ import fetch from 'isomorphic-unfetch'; -import { graphQlHost } from './config'; +import { store, graphQlHost } from './config'; import GraphQlQuery from './types/GraphQlQuery'; function fetchWithGraphQl(query: GraphQlQuery, token: string | null = null): Promise { @@ -12,7 +12,7 @@ function fetchWithGraphQl(query: GraphQlQuery, token: string | null = null): Pro ...authHeaders, Accept: 'application/json', 'Content-Type': 'application/json', - Store: 'default', + Store: store, }, body: JSON.stringify(query), }).then((res) => res.json()); From 01ab4f5fda54110708644152e4dcab0b019472e6 Mon Sep 17 00:00:00 2001 From: Aaron Croissette Date: Mon, 19 Jul 2021 12:07:58 -0400 Subject: [PATCH 2/3] Set default value for store view to "default" --- src/fetchWithGraphQl.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fetchWithGraphQl.ts b/src/fetchWithGraphQl.ts index cfc51ac..e1f92cf 100644 --- a/src/fetchWithGraphQl.ts +++ b/src/fetchWithGraphQl.ts @@ -12,7 +12,7 @@ function fetchWithGraphQl(query: GraphQlQuery, token: string | null = null): Pro ...authHeaders, Accept: 'application/json', 'Content-Type': 'application/json', - Store: store, + Store: store ? store : 'default', }, body: JSON.stringify(query), }).then((res) => res.json()); From 0ad2f9a218ad528da0d56a970e898635646c6d6a Mon Sep 17 00:00:00 2001 From: Aaron Croissette Date: Mon, 19 Jul 2021 12:10:01 -0400 Subject: [PATCH 3/3] Update .env.sample with M2_CONFIG_STORE default --- .env.sample | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.env.sample b/.env.sample index e68f244..2d36713 100644 --- a/.env.sample +++ b/.env.sample @@ -1 +1,2 @@ -M2_CONFIG_HOST=https://www.your-magento-site.com \ No newline at end of file +M2_CONFIG_HOST=https://www.your-magento-site.com +M2_CONFIG_STORE=default