Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix docs for AdminApiContext. Previously they pointed to a type that… #2023

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,7 @@
},
"jsDocTypeExamples": [
"EmbeddedAdminContext",
"AdminApiContextWithRest",
"AdminApiContextWithoutRest",
"BillingContext",
"ScopesApiContext"
Expand Down Expand Up @@ -1319,6 +1320,106 @@
}
]
},
{
"title": "rest",
"examples": [
{
"description": "Getting the number of orders in a store using REST resources. Visit the [Admin REST API references](/docs/api/admin-rest) for examples on using each resource.",
"codeblock": {
"title": "Using REST resources",
"tabs": [
{
"title": "/app/routes/**\\/*.ts",
"code": "import { LoaderFunctionArgs, json } from \"@remix-run/node\";\nimport { authenticate } from \"../shopify.server\";\n\nexport const loader = async ({ request }: LoaderFunctionArgs) => {\n const {\n admin,\n session,\n } = await authenticate.admin(request);\n\n return json(\n admin.rest.resources.Order.count({ session }),\n );\n};",
"language": "typescript"
},
{
"title": "/app/shopify.server.ts",
"code": "import { shopifyApp } from \"@shopify/shopify-app-remix/server\";\nimport { restResources } from \"@shopify/shopify-api/rest/admin/2023-07\";\n\nconst shopify = shopifyApp({\n restResources,\n // ...etc\n});\nexport default shopify;\nexport const authenticate = shopify.authenticate;",
"language": "typescript"
}
]
}
},
{
"description": "Use `admin.rest.get` to make custom requests to make a request to to the `customer/count` endpoint",
"codeblock": {
"title": "Performing a GET request to the REST API",
"tabs": [
{
"title": "/app/routes/**\\/*.ts",
"code": "import { LoaderFunctionArgs, json } from \"@remix-run/node\";\nimport { authenticate } from \"../shopify.server\";\n\nexport const loader = async ({ request }: LoaderFunctionArgs) => {\n const {\n admin,\n session,\n } = await authenticate.admin(request);\n\n const response = await admin.rest.get({\n path: \"/customers/count.json\",\n });\n const customers = await response.json();\n\n return json({ customers });\n};",
"language": "typescript"
},
{
"title": "/app/shopify.server.ts",
"code": "import { shopifyApp } from \"@shopify/shopify-app-remix/server\";\nimport { restResources } from \"@shopify/shopify-api/rest/admin/2023-04\";\n\nconst shopify = shopifyApp({\n restResources,\n // ...etc\n});\nexport default shopify;\nexport const authenticate = shopify.authenticate;",
"language": "typescript"
}
]
}
},
{
"description": "Use `admin.rest.post` to make custom requests to make a request to to the `customers.json` endpoint to send a welcome email",
"codeblock": {
"title": "Performing a POST request to the REST API",
"tabs": [
{
"title": "/app/routes/**\\/*.ts",
"code": "import { LoaderFunctionArgs, json } from \"@remix-run/node\";\nimport { authenticate } from \"../shopify.server\";\n\nexport const loader = async ({ request }: LoaderFunctionArgs) => {\n const {\n admin,\n session,\n } = await authenticate.admin(request);\n\n const response = admin.rest.post({\n path: \"customers/7392136888625/send_invite.json\",\n body: {\n customer_invite: {\n to: \"[email protected]\",\n from: \"[email protected]\",\n bcc: [\"[email protected]\"],\n subject: \"Welcome to my new shop\",\n custom_message: \"My awesome new store\",\n },\n },\n });\n\n const customerInvite = await response.json();\n return json({ customerInvite });\n};",
"language": "typescript"
},
{
"title": "/app/shopify.server.ts",
"code": "import { shopifyApp } from \"@shopify/shopify-app-remix/server\";\nimport { restResources } from \"@shopify/shopify-api/rest/admin/2023-04\";\n\nconst shopify = shopifyApp({\n restResources,\n // ...etc\n});\nexport default shopify;\nexport const authenticate = shopify.authenticate;",
"language": "typescript"
}
]
}
}
]
},
{
"title": "graphql",
"examples": [
{
"description": "Use `admin.graphql` to make query / mutation requests.",
"codeblock": {
"title": "Querying the GraphQL API",
"tabs": [
{
"title": "/app/routes/**\\/*.ts",
"code": "import { ActionFunctionArgs } from \"@remix-run/node\";\nimport { authenticate } from \"../shopify.server\";\n\nexport const action = async ({ request }: ActionFunctionArgs) => {\n const { admin } = await authenticate.admin(request);\n\n const response = await admin.graphql(\n `#graphql\n mutation populateProduct($input: ProductInput!) {\n productCreate(input: $input) {\n product {\n id\n }\n }\n }`,\n {\n variables: {\n input: { title: \"Product Name\" },\n },\n },\n );\n\n const productData = await response.json();\n return json({\n productId: productData.data?.productCreate?.product?.id,\n });\n}",
"language": "typescript"
},
{
"title": "/app/shopify.server.ts",
"code": "import { shopifyApp } from \"@shopify/shopify-app-remix/server\";\n\nconst shopify = shopifyApp({\n // ...\n});\nexport default shopify;\nexport const authenticate = shopify.authenticate;",
"language": "typescript"
}
]
}
},
{
"description": "Catch `GraphqlQueryError` errors to see error messages from the API.",
"codeblock": {
"title": "Handling GraphQL errors",
"tabs": [
{
"title": "/app/routes/**\\/*.ts",
"code": "import { ActionFunctionArgs } from \"@remix-run/node\";\nimport { authenticate } from \"../shopify.server\";\n\nexport const action = async ({ request }: ActionFunctionArgs) => {\n const { admin } = await authenticate.admin(request);\n\n try {\n const response = await admin.graphql(\n `#graphql\n query incorrectQuery {\n products(first: 10) {\n nodes {\n not_a_field\n }\n }\n }`,\n );\n\n return json({ data: await response.json() });\n } catch (error) {\n if (error instanceof GraphqlQueryError) {\n // error.body.errors:\n // { graphQLErrors: [\n // { message: \"Field 'not_a_field' doesn't exist on type 'Product'\" }\n // ] }\n return json({ errors: error.body?.errors }, { status: 500 });\n }\n return json({ message: \"An error occurred\" }, { status: 500 });\n }\n}",
"language": "typescript"
},
{
"title": "/app/shopify.server.ts",
"code": "import { shopifyApp } from \"@shopify/shopify-app-remix/server\";\n\nconst shopify = shopifyApp({\n // ...\n});\nexport default shopify;\nexport const authenticate = shopify.authenticate;",
"language": "typescript"
}
]
}
}
]
},
{
"title": "cancel",
"examples": [
Expand Down Expand Up @@ -8300,8 +8401,13 @@
"filePath": "../shopify-api/dist/ts/lib/types.d.ts",
"syntaxKind": "EnumDeclaration",
"name": "ApiVersion",
"value": "export declare enum ApiVersion {\n October22 = \"2022-10\",\n January23 = \"2023-01\",\n April23 = \"2023-04\",\n July23 = \"2023-07\",\n October23 = \"2023-10\",\n January24 = \"2024-01\",\n April24 = \"2024-04\",\n July24 = \"2024-07\",\n October24 = \"2024-10\",\n January25 = \"2025-01\",\n Unstable = \"unstable\"\n}",
"value": "export declare enum ApiVersion {\n January25 = \"2025-01\",\n October22 = \"2022-10\",\n January23 = \"2023-01\",\n April23 = \"2023-04\",\n July23 = \"2023-07\",\n October23 = \"2023-10\",\n January24 = \"2024-01\",\n April24 = \"2024-04\",\n July24 = \"2024-07\",\n October24 = \"2024-10\",\n Unstable = \"unstable\"\n}",
"members": [
{
"filePath": "../shopify-api/dist/ts/lib/types.d.ts",
"name": "January25",
"value": "2025-01"
},
{
"filePath": "../shopify-api/dist/ts/lib/types.d.ts",
"name": "October22",
Expand Down Expand Up @@ -8347,11 +8453,6 @@
"name": "October24",
"value": "2024-10"
},
{
"filePath": "../shopify-api/dist/ts/lib/types.d.ts",
"name": "January25",
"value": "2025-01"
},
{
"filePath": "../shopify-api/dist/ts/lib/types.d.ts",
"name": "Unstable",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const data: ReferenceEntityTemplateSchema = {
},
jsDocTypeExamples: [
'EmbeddedAdminContext',
'AdminApiContextWithRest',
'AdminApiContextWithoutRest',
'BillingContext',
'ScopesApiContext',
Expand Down
Loading