-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #442 from Shopify/add-storefront-client
Add storefront client
- Loading branch information
Showing
40 changed files
with
2,052 additions
and
1,810 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
'@shopify/shopify-app-remix': minor | ||
--- | ||
|
||
Added the storefront GraphQL client. | ||
|
||
The storefront API client can be accessed in two ways | ||
|
||
<details> | ||
<summary>App Proxy</summary> | ||
|
||
```ts | ||
import {json} from '@remix-run/node'; | ||
import {authenticate} from '~/shopify.server'; | ||
|
||
export async function loader({request}) { | ||
const {storefront} = await authenticate.public.appProxy(request); | ||
const response = await storefront.graphql('{blogs(first: 10) {nodes{id}}}'); | ||
|
||
return json(await response.json()); | ||
} | ||
``` | ||
|
||
</details> | ||
|
||
<details> | ||
<summary>Unauthenticated Storefront</summary> | ||
|
||
```ts | ||
import {json} from '@remix-run/node'; | ||
import {unauthenticated} from '~/shopify.server'; | ||
import {customAuthenticateRequest} from '~/helpers'; | ||
|
||
export async function loader({request}) { | ||
await customAuthenticateRequest(request); | ||
|
||
const {storefront} = await unauthenticated.storefront( | ||
'my-shop.myshopify.com', | ||
); | ||
const response = await storefront.graphql('{blogs(first: 10) {nodes{id}}}'); | ||
|
||
return json(await response.json()); | ||
} | ||
``` | ||
|
||
</details> |
2,957 changes: 1,381 additions & 1,576 deletions
2,957
packages/shopify-app-remix/docs/generated/generated_docs_data.json
Large diffs are not rendered by default.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
packages/shopify-app-remix/src/server/__test-helpers/expect-admin-api-client.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
packages/shopify-app-remix/src/server/__test-helpers/expect-storefront-api-client.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import {Session} from '@shopify/shopify-api'; | ||
|
||
import {LATEST_API_VERSION} from '..'; | ||
import type {StorefrontContext} from '../clients'; | ||
|
||
import {mockExternalRequest} from './request-mock'; | ||
import {TEST_SHOP} from './const'; | ||
|
||
export function expectStorefrontApiClient( | ||
factory: () => Promise<{ | ||
storefront: StorefrontContext; | ||
expectedSession: Session; | ||
actualSession: Session; | ||
}>, | ||
) { | ||
it('Storefront client can perform GraphQL Requests', async () => { | ||
// GIVEN | ||
const {storefront, actualSession} = await factory(); | ||
const apiResponse = {blogs: {nodes: [{id: 1}]}}; | ||
await mockExternalRequest({ | ||
request: new Request( | ||
`https://${TEST_SHOP}/api/${LATEST_API_VERSION}/graphql.json`, | ||
{ | ||
method: 'POST', | ||
headers: { | ||
'Shopify-Storefront-Private-Token': actualSession.accessToken!, | ||
}, | ||
}, | ||
), | ||
response: new Response(JSON.stringify(apiResponse)), | ||
}); | ||
|
||
// WHEN | ||
const response = await storefront.graphql( | ||
'blogs(first: 1) { nodes { id }}', | ||
); | ||
|
||
// THEN | ||
expect(response.status).toEqual(200); | ||
expect(await response.json()).toEqual(apiResponse); | ||
}); | ||
|
||
it('Storefront client uses the correct session', async () => { | ||
// GIVEN | ||
const {expectedSession, actualSession} = await factory(); | ||
|
||
// THEN | ||
expect(expectedSession).toEqual(actualSession); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.