Skip to content

Commit

Permalink
Propagating changes after v9 release
Browse files Browse the repository at this point in the history
  • Loading branch information
paulomarg committed Jan 10, 2024
1 parent 351b9ae commit 04b0f05
Show file tree
Hide file tree
Showing 30 changed files with 90 additions and 72 deletions.
2 changes: 2 additions & 0 deletions .changeset/thirty-apples-think.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
---

Adding support for the new clients from `@shopify/admin-api-client` and `@shopify/storefront-api-client` that can leverage `@shopify/api-codegen-preset` to automatically type GraphQL operations using Codegen.

For more information on how to add types to your queries, see [the `@shopify/api-codegen-preset` documentation](https://github.com/Shopify/shopify-api-js/tree/main/packages/api-codegen-preset).
2 changes: 1 addition & 1 deletion packages/shopify-app-express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"Storefront API"
],
"dependencies": {
"@shopify/shopify-api": "^8.1.1",
"@shopify/shopify-api": "^9.0.0",
"@shopify/shopify-app-session-storage": "^2.0.2",
"@shopify/shopify-app-session-storage-memory": "^2.0.2",
"cookie-parser": "^1.4.6",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ function assertOAuthRequests(
expect({
method: 'POST',
url: `https://${TEST_SHOP}/admin/api/${LATEST_API_VERSION}/graphql.json`,
body: expect.stringContaining(query),
body: expect.objectContaining({query: expect.stringContaining(query)}),
}).toMatchMadeHttpRequest(),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ describe('webhook integration', () => {
expect({
method: 'POST',
url: `https://${TEST_SHOP}/admin/api/${LATEST_API_VERSION}/graphql.json`,
body: expect.stringContaining(query),
body: expect.objectContaining({
query: expect.stringContaining(query),
}),
}).toMatchMadeHttpRequest(),
);

Expand Down
13 changes: 11 additions & 2 deletions packages/shopify-app-express/src/__tests__/test-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ interface AssertHttpRequestParams {
export function mockShopifyResponse(body: MockBody, init?: MockParams) {
fetchMock.mockResponse(
typeof body === 'string' ? body : JSON.stringify(body),
init,
mockResponseInit(init),
);
}

Expand All @@ -84,13 +84,22 @@ export function mockShopifyResponses(
([body, init]) => {
const bodyString = typeof body === 'string' ? body : JSON.stringify(body);

return init ? [bodyString, init] : [bodyString, {}];
return [bodyString, mockResponseInit(init)];
},
);

fetchMock.mockResponses(...parsedResponses);
}

function mockResponseInit(init?: MockParams): MockParams {
const initObj = init ?? {};

return {
...initObj,
headers: {'Content-Type': 'application/json', ...initObj.headers},
};
}

declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace jest {
Expand Down
4 changes: 2 additions & 2 deletions packages/shopify-app-express/src/auth/auth-callback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {Request, Response} from 'express';
import {
BotActivityDetected,
CookieNotFound,
gdprTopics,
privacyTopics,
InvalidOAuthError,
Session,
Shopify,
Expand Down Expand Up @@ -83,7 +83,7 @@ async function registerWebhooks(
}

for (const response of responsesByTopic[topic]) {
if (!response.success && !gdprTopics.includes(topic)) {
if (!response.success && !privacyTopics.includes(topic)) {
const result: any = response.result;

if (result.errors) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,10 @@ describe('ensureInstalledOnShop', () => {
)}`,
];

mockShopifyResponse({});
mockShopifyResponse({
data: {},
extensions: {},
});
await shopify.config.sessionStorage.storeSession(session);

await request(app)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,10 @@ describe('validateAuthenticatedSession', () => {
});

it('finds a session with the right cookie', async () => {
mockShopifyResponse({});
mockShopifyResponse({
data: {},
extensions: {},
});

const response = await request(app)
.get('/test/shop?shop=my-shop.myshopify.io')
Expand Down
6 changes: 3 additions & 3 deletions packages/shopify-app-remix/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@
},
"dependencies": {
"@remix-run/server-runtime": "^2.0.0",
"@shopify/admin-api-client": "^0.1.0",
"@shopify/shopify-api": "^8.1.1",
"@shopify/admin-api-client": "^0.2.0",
"@shopify/shopify-api": "^9.0.0",
"@shopify/shopify-app-session-storage": "^2.0.2",
"@shopify/storefront-api-client": "^0.1.1",
"@shopify/storefront-api-client": "^0.2.0",
"isbot": "^3.7.1",
"semver": "^7.5.4",
"tslib": "^2.6.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,17 @@ export function expectAdminApiClient(
headers: {'X-Shopify-Access-Token': actualSession.accessToken!},
},
),
response: new Response(JSON.stringify({shop: {name: 'Test shop'}})),
response: new Response(
JSON.stringify({data: {shop: {name: 'Test shop'}}}),
),
});

// WHEN
const response = await admin.graphql('{ shop { name } }');

// THEN
expect(response.status).toEqual(200);
expect(await response.json()).toEqual({shop: {name: 'Test shop'}});
expect(await response.json()).toEqual({data: {shop: {name: 'Test shop'}}});
});

it('returns a session object as part of the context', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function expectStorefrontApiClient(
it('Storefront client can perform GraphQL Requests', async () => {
// GIVEN
const {storefront, actualSession} = await factory();
const apiResponse = {blogs: {nodes: [{id: 1}]}};
const apiResponse = {data: {blogs: {nodes: [{id: 1}]}}};
await mockExternalRequest({
request: new Request(
`https://${TEST_SHOP}/api/${LATEST_API_VERSION}/graphql.json`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ async function mockParams(response: Response): Promise<ResponseParams> {
status: response.status,
statusText: response.statusText,
url: response.url,
headers: Object.fromEntries(response.headers.entries()),
headers: {
...Object.fromEntries(response.headers.entries()),
'content-type': 'application/json',
},
},
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ async function mockRestRequest(status) {

await mockExternalRequest({
request: requestMock,
response: new Response(undefined, {status}),
response: new Response('{}', {status}),
});

return requestMock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ describe('authorize.admin doc request path', () => {

await mockExternalRequest({
request: new Request(GRAPHQL_URL, {method: 'POST'}),
response: new Response(
JSON.stringify({errors: [{message: 'Something went wrong!'}]}),
{status: 500, statusText: 'Internal Server Error'},
),
response: new Response('', {
status: 500,
statusText: 'Internal Server Error',
}),
});

// WHEN
Expand All @@ -96,7 +96,7 @@ describe('authorize.admin doc request path', () => {
expect(response.status).toBe(500);
expect(config.logger?.log).toHaveBeenCalledWith(
LogSeverity.Error,
expect.stringContaining('Something went wrong!'),
expect.stringContaining('Internal Server Error'),
);
});

Expand All @@ -109,7 +109,7 @@ describe('authorize.admin doc request path', () => {
await mockExternalRequest({
request: new Request(GRAPHQL_URL, {method: 'POST'}),
response: new Response(
JSON.stringify({errors: ['Something went wrong!']}),
JSON.stringify({errors: [{message: 'Something went wrong!'}]}),
),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export class AuthCodeFlowStrategy<
session,
});

await client.query(`#graphql
await client.request(`#graphql
query shopifyAppShopName {
shop {
name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ describe('Webhook registration', () => {
body: 'webhookSubscriptionCreate',
}),
response: new Response(
JSON.stringify({
body: mockResponses.HTTP_WEBHOOK_CREATE_ERROR_RESPONSE,
}),
JSON.stringify(mockResponses.HTTP_WEBHOOK_CREATE_ERROR_RESPONSE),
),
},
);
Expand Down
11 changes: 4 additions & 7 deletions packages/shopify-app-remix/src/server/clients/admin/graphql.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {flatHeaders} from '@shopify/shopify-api/runtime';
import {AdminOperations} from '@shopify/admin-api-client';

import {GraphQLClient} from '../types';
Expand All @@ -22,15 +21,13 @@ export function graphqlClientFactory({

try {
// We convert the incoming response to a Response object to bring this client closer to the Remix client.
const apiResponse = await client.query(operation, {
const apiResponse = await client.request(operation, {
variables: options?.variables,
tries: options?.tries,
extraHeaders: options?.headers,
retries: options?.tries ? options.tries - 1 : 0,
headers: options?.headers,
});

return new Response(JSON.stringify(apiResponse.body), {
headers: flatHeaders(apiResponse.headers),
});
return new Response(JSON.stringify(apiResponse));
} catch (error) {
if (handleClientError) {
throw await handleClientError({error, params, session});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {flatHeaders} from '@shopify/shopify-api/runtime';
import {Session} from '@shopify/shopify-api';

import {BasicParams} from '../../types';
Expand All @@ -21,15 +20,13 @@ export function storefrontClientFactory({
apiVersion: options.apiVersion,
});

const apiResponse = await client.query(query, {
const apiResponse = await client.request(query, {
variables: options?.variables,
tries: options?.tries,
extraHeaders: options?.headers,
retries: options?.tries ? options.tries - 1 : 0,
headers: options?.headers,
});

return new Response(JSON.stringify(apiResponse.body), {
headers: flatHeaders(apiResponse.headers),
});
return new Response(JSON.stringify(apiResponse));
},
};
}
4 changes: 2 additions & 2 deletions packages/shopify-app-session-storage-dynamodb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@
"tslib": "^2.6.2"
},
"peerDependencies": {
"@shopify/shopify-api": "^8.1.1",
"@shopify/shopify-api": "^9.0.0",
"@shopify/shopify-app-session-storage": "^2.0.2"
},
"devDependencies": {
"@shopify/eslint-plugin": "^42.1.0",
"@shopify/prettier-config": "^1.1.2",
"@shopify/shopify-api": "^8.1.1",
"@shopify/shopify-api": "^9.0.0",
"@shopify/shopify-app-session-storage": "^2.0.2",
"@shopify/shopify-app-session-storage-test-utils": "^1.0.2",
"eslint": "^8.55.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/shopify-app-session-storage-kv/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"tslib": "^2.6.2"
},
"peerDependencies": {
"@shopify/shopify-api": "^8.1.1",
"@shopify/shopify-api": "^9.0.0",
"@shopify/shopify-app-session-storage": "^2.0.2"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/shopify-app-session-storage-memory/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"tslib": "^2.6.2"
},
"peerDependencies": {
"@shopify/shopify-api": "^8.1.1",
"@shopify/shopify-api": "^9.0.0",
"@shopify/shopify-app-session-storage": "^2.0.2"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/shopify-app-session-storage-mongodb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"tslib": "^2.6.2"
},
"peerDependencies": {
"@shopify/shopify-api": "^8.1.1",
"@shopify/shopify-api": "^9.0.0",
"@shopify/shopify-app-session-storage": "^2.0.2"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/shopify-app-session-storage-mysql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"tslib": "^2.6.2"
},
"peerDependencies": {
"@shopify/shopify-api": "^8.1.1",
"@shopify/shopify-api": "^9.0.0",
"@shopify/shopify-app-session-storage": "^2.0.2"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"tslib": "^2.6.2"
},
"peerDependencies": {
"@shopify/shopify-api": "^8.1.1",
"@shopify/shopify-api": "^9.0.0",
"@shopify/shopify-app-session-storage": "^2.0.2"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/shopify-app-session-storage-prisma/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
},
"peerDependencies": {
"@prisma/client": "^4.13.0",
"@shopify/shopify-api": "^8.1.1",
"@shopify/shopify-api": "^9.0.0",
"@shopify/shopify-app-session-storage": "^2.0.2",
"prisma": "^4.13.0"
},
"devDependencies": {
"@prisma/client": "^4.13.0",
"@shopify/shopify-api": "^8.1.1",
"@shopify/shopify-api": "^9.0.0",
"@shopify/shopify-app-session-storage": "^2.0.2",
"prisma": "^4.13.0",
"@shopify/eslint-plugin": "^42.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/shopify-app-session-storage-redis/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"tslib": "^2.6.2"
},
"peerDependencies": {
"@shopify/shopify-api": "^8.1.1",
"@shopify/shopify-api": "^9.0.0",
"@shopify/shopify-app-session-storage": "^2.0.2"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/shopify-app-session-storage-sqlite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"tslib": "^2.6.2"
},
"peerDependencies": {
"@shopify/shopify-api": "^8.1.1",
"@shopify/shopify-api": "^9.0.0",
"@shopify/shopify-app-session-storage": "^2.0.2"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"tslib": "^2.6.2"
},
"peerDependencies": {
"@shopify/shopify-api": "^8.1.1",
"@shopify/shopify-api": "^9.0.0",
"@shopify/shopify-app-session-storage": "^2.0.2"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/shopify-app-session-storage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"tslib": "^2.6.2"
},
"peerDependencies": {
"@shopify/shopify-api": "^8.1.1"
"@shopify/shopify-api": "^9.0.0"
},
"devDependencies": {
"@shopify/eslint-plugin": "^42.1.0",
Expand Down
Loading

0 comments on commit 04b0f05

Please sign in to comment.