@shopify/shop-minis-cli 0.0.131 → 0.0.133
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/commands/generate-graphql-types/utils/get-graphql-config.js +22 -2
- package/build/commands/generate-graphql-types/utils/get-graphql-config.js.map +1 -1
- package/build/commands/generate-graphql-types/utils/get-graphql-config.spec.d.ts +1 -0
- package/build/commands/generate-graphql-types/utils/get-graphql-config.spec.js +57 -0
- package/build/commands/generate-graphql-types/utils/get-graphql-config.spec.js.map +1 -0
- package/package.json +1 -1
- package/templates/extensions/components/__template_survey-single-response/render.tsx +26 -0
- package/templates/extensions/components/__template_survey-single-response/seed.ts +22 -0
|
@@ -1,11 +1,31 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
1
2
|
import { createRequire } from 'node:module';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { outputDebug } from '@shopify/cli-kit/node/output';
|
|
5
|
+
const customRequire = () => createRequire(import.meta.url);
|
|
2
6
|
export function getGraphqlConfig() {
|
|
3
7
|
try {
|
|
4
|
-
|
|
8
|
+
let gqlConfig;
|
|
9
|
+
const localConfigPath = join(process.cwd(), '.graphqlrc.js');
|
|
10
|
+
const localConfigExists = existsSync(localConfigPath);
|
|
11
|
+
outputDebug(`Local graphql config from ${localConfigPath} exists? ${localConfigExists}`);
|
|
12
|
+
if (localConfigExists) {
|
|
13
|
+
outputDebug(`Using local graphql config from ${localConfigPath}`);
|
|
14
|
+
try {
|
|
15
|
+
gqlConfig = customRequire()(localConfigPath);
|
|
16
|
+
}
|
|
17
|
+
catch (err) {
|
|
18
|
+
outputDebug(`Failed to load local graphql config from ${localConfigPath}. Error ${err}`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (!gqlConfig) {
|
|
22
|
+
outputDebug(`Using graphql config from @shopify/shop-minis-runtime/graphqlrc`);
|
|
23
|
+
gqlConfig = customRequire()('@shopify/shop-minis-runtime/graphqlrc');
|
|
24
|
+
}
|
|
5
25
|
return gqlConfig;
|
|
6
26
|
}
|
|
7
27
|
catch (err) {
|
|
8
|
-
throw new Error(
|
|
28
|
+
throw new Error(`Failed to load graphql config from "@shopify/shop-minis-runtime/graphqlrc". Error: ${err}`);
|
|
9
29
|
}
|
|
10
30
|
}
|
|
11
31
|
//# sourceMappingURL=get-graphql-config.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-graphql-config.js","sourceRoot":"","sources":["../../../../src/commands/generate-graphql-types/utils/get-graphql-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"get-graphql-config.js","sourceRoot":"","sources":["../../../../src/commands/generate-graphql-types/utils/get-graphql-config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,MAAM,SAAS,CAAA;AAClC,OAAO,EAAC,aAAa,EAAC,MAAM,aAAa,CAAA;AACzC,OAAO,EAAC,IAAI,EAAC,MAAM,WAAW,CAAA;AAE9B,OAAO,EAAC,WAAW,EAAC,MAAM,8BAA8B,CAAA;AAExD,MAAM,aAAa,GAAG,GAAG,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAE1D,MAAM,UAAU,gBAAgB;IAC9B,IAAI;QACF,IAAI,SAAS,CAAA;QACb,MAAM,eAAe,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,eAAe,CAAC,CAAA;QAC5D,MAAM,iBAAiB,GAAG,UAAU,CAAC,eAAe,CAAC,CAAA;QACrD,WAAW,CACT,6BAA6B,eAAe,YAAY,iBAAiB,EAAE,CAC5E,CAAA;QAED,IAAI,iBAAiB,EAAE;YACrB,WAAW,CAAC,mCAAmC,eAAe,EAAE,CAAC,CAAA;YAEjE,IAAI;gBACF,SAAS,GAAG,aAAa,EAAE,CAAC,eAAe,CAAC,CAAA;aAC7C;YAAC,OAAO,GAAG,EAAE;gBACZ,WAAW,CACT,4CAA4C,eAAe,WAAW,GAAG,EAAE,CAC5E,CAAA;aACF;SACF;QAED,IAAI,CAAC,SAAS,EAAE;YACd,WAAW,CACT,iEAAiE,CAClE,CAAA;YACD,SAAS,GAAG,aAAa,EAAE,CAAC,uCAAuC,CAAC,CAAA;SACrE;QAED,OAAO,SAAS,CAAA;KACjB;IAAC,OAAO,GAAG,EAAE;QACZ,MAAM,IAAI,KAAK,CACb,sFAAsF,GAAG,EAAE,CAC5F,CAAA;KACF;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { expect, describe, it, vi, afterEach } from 'vitest';
|
|
4
|
+
import { getGraphqlConfig } from './get-graphql-config.js';
|
|
5
|
+
const customRequireMock = vi.fn();
|
|
6
|
+
vi.mock('node:module', () => ({
|
|
7
|
+
createRequire: vi.fn(() => {
|
|
8
|
+
return customRequireMock;
|
|
9
|
+
}),
|
|
10
|
+
}));
|
|
11
|
+
vi.mock('node:fs');
|
|
12
|
+
vi.mock('@shopify/cli-kit/node/output');
|
|
13
|
+
const localConfigPath = join(process.cwd(), '.graphqlrc.js');
|
|
14
|
+
const runtimeConfigPath = '@shopify/shop-minis-runtime/graphqlrc';
|
|
15
|
+
describe('getGraphqlConfig', () => {
|
|
16
|
+
afterEach(() => {
|
|
17
|
+
vi.clearAllMocks();
|
|
18
|
+
});
|
|
19
|
+
it('should use local graphql config if it exists', () => {
|
|
20
|
+
const mockConfig = { local: 'config' };
|
|
21
|
+
vi.mocked(existsSync).mockReturnValue(true);
|
|
22
|
+
vi.mocked(customRequireMock).mockReturnValue(mockConfig);
|
|
23
|
+
const result = getGraphqlConfig();
|
|
24
|
+
expect(customRequireMock).toHaveBeenCalledWith(localConfigPath);
|
|
25
|
+
expect(result).toEqual(mockConfig);
|
|
26
|
+
});
|
|
27
|
+
it('should use runtime graphql config if local config does not exist', () => {
|
|
28
|
+
const mockConfig = { runtime: 'config' };
|
|
29
|
+
vi.mocked(existsSync).mockReturnValue(false);
|
|
30
|
+
vi.mocked(customRequireMock).mockReturnValue(mockConfig);
|
|
31
|
+
const result = getGraphqlConfig();
|
|
32
|
+
expect(customRequireMock).toHaveBeenCalledWith(runtimeConfigPath);
|
|
33
|
+
expect(result).toEqual(mockConfig);
|
|
34
|
+
});
|
|
35
|
+
it('uses the runtime config if the local require fails', () => {
|
|
36
|
+
const mockConfig = { runtime: 'config' };
|
|
37
|
+
vi.mocked(existsSync).mockReturnValue(true);
|
|
38
|
+
vi.mocked(customRequireMock).mockImplementation(requirePath => {
|
|
39
|
+
if (requirePath === localConfigPath) {
|
|
40
|
+
throw new Error('Mock error requiring local config');
|
|
41
|
+
}
|
|
42
|
+
return mockConfig;
|
|
43
|
+
});
|
|
44
|
+
const result = getGraphqlConfig();
|
|
45
|
+
expect(customRequireMock).toHaveBeenCalledWith(localConfigPath);
|
|
46
|
+
expect(customRequireMock).toHaveBeenCalledWith(runtimeConfigPath);
|
|
47
|
+
expect(result).toEqual(mockConfig);
|
|
48
|
+
});
|
|
49
|
+
it('should throw an error if both local and runtime configs fail to load', () => {
|
|
50
|
+
vi.mocked(existsSync).mockReturnValue(true);
|
|
51
|
+
vi.mocked(customRequireMock).mockImplementation(() => {
|
|
52
|
+
throw new Error('Mock error message');
|
|
53
|
+
});
|
|
54
|
+
expect(() => getGraphqlConfig()).toThrow(`Failed to load graphql config from "@shopify/shop-minis-runtime/graphqlrc". Error: Error: Mock error message`);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
//# sourceMappingURL=get-graphql-config.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-graphql-config.spec.js","sourceRoot":"","sources":["../../../../src/commands/generate-graphql-types/utils/get-graphql-config.spec.ts"],"names":[],"mappings":"AAAA,OA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,CAAC,CAAA;IACpC,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,sEAAsE,EAAE,GAAG,EAAE;QAC9E,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,eAAe,CAAC,IAAI,CAAC,CAAA;QAC3C,EAAE,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,kBAAkB,CAAC,GAAG,EAAE;YACnD,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAA;QACvC,CAAC,CAAC,CAAA;QAEF,MAAM,CAAC,GAAG,EAAE,CAAC,gBAAgB,EAAE,CAAC,CAAC,OAAO,CACtC,8GAA8G,CAC/G,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {SurveySingleResponse} from '@shopify/shop-minis-ui-extensions'
|
|
2
|
+
|
|
3
|
+
import type {__QUERY_NAME__QueryData} from './input.graphql'
|
|
4
|
+
import seedData from './seed'
|
|
5
|
+
|
|
6
|
+
export function Render({
|
|
7
|
+
extensionData,
|
|
8
|
+
}: {
|
|
9
|
+
extensionData: __QUERY_NAME__QueryData | null
|
|
10
|
+
}) {
|
|
11
|
+
// Here we are using seed data to populate the initial state of the survey.
|
|
12
|
+
// You can replace this with the actual data from `extensionData`
|
|
13
|
+
__EXAMPLE_QUERY_DATA_USE__
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<SurveySingleResponse
|
|
17
|
+
choices={seedData}
|
|
18
|
+
onChoiceSelected={(index, value) =>
|
|
19
|
+
console.log('Selected:', index, value)
|
|
20
|
+
}
|
|
21
|
+
title="How did you find our store?"
|
|
22
|
+
seeMoreChoice={{label: 'Other', value: 'seeMore'}}
|
|
23
|
+
singleQuestionSurvey={false}
|
|
24
|
+
/>
|
|
25
|
+
)
|
|
26
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const MINIS_TEST_STORE_DATA = {
|
|
2
|
+
id: 'gid://shopify/Shop/62104633599',
|
|
3
|
+
image: null,
|
|
4
|
+
name: 'Shop Minis Test Store',
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const data = [
|
|
8
|
+
{label: 'Google', value: 'google'},
|
|
9
|
+
{label: 'Facebook', value: 'facebook'},
|
|
10
|
+
{label: 'Pinterest', value: 'pinterest'},
|
|
11
|
+
{label: 'Instagram', value: 'instagram'},
|
|
12
|
+
{label: 'Snapchat', value: 'snapchat'},
|
|
13
|
+
{label: 'TikTok', value: 'tikTok'},
|
|
14
|
+
{label: 'From a friend, family member or coworker', value: 'friends'},
|
|
15
|
+
{label: 'In a retail store', value: 'store'},
|
|
16
|
+
{label: 'Podcast/Radio', value: 'podcast'},
|
|
17
|
+
{label: 'Press or other article', value: 'press'},
|
|
18
|
+
{label: 'Youtube', value: 'youtube'},
|
|
19
|
+
{label: 'Other', value: 'other'},
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
export default data
|