shop-cli 0.1.1
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/LICENSE +21 -0
- package/README.md +392 -0
- package/bin/shop-cli.js +17 -0
- package/bin/shop.js +16 -0
- package/dist/adminClient.d.ts +34 -0
- package/dist/adminClient.js +144 -0
- package/dist/cli/client.d.ts +10 -0
- package/dist/cli/client.js +56 -0
- package/dist/cli/command.d.ts +5 -0
- package/dist/cli/command.js +62 -0
- package/dist/cli/errors.d.ts +4 -0
- package/dist/cli/errors.js +35 -0
- package/dist/cli/gid.d.ts +3 -0
- package/dist/cli/gid.js +42 -0
- package/dist/cli/globalFlags.d.ts +15 -0
- package/dist/cli/globalFlags.js +100 -0
- package/dist/cli/headers.d.ts +2 -0
- package/dist/cli/headers.js +79 -0
- package/dist/cli/help/format.d.ts +8 -0
- package/dist/cli/help/format.js +78 -0
- package/dist/cli/help/registry.d.ts +5 -0
- package/dist/cli/help/registry.js +6443 -0
- package/dist/cli/help/render.d.ts +8 -0
- package/dist/cli/help/render.js +399 -0
- package/dist/cli/help/spec.d.ts +39 -0
- package/dist/cli/help/spec.js +17 -0
- package/dist/cli/input.d.ts +9 -0
- package/dist/cli/input.js +104 -0
- package/dist/cli/introspection/deprecations.d.ts +1 -0
- package/dist/cli/introspection/deprecations.js +83 -0
- package/dist/cli/introspection/format.d.ts +6 -0
- package/dist/cli/introspection/format.js +63 -0
- package/dist/cli/introspection/index.d.ts +14 -0
- package/dist/cli/introspection/index.js +89 -0
- package/dist/cli/introspection/resources.d.ts +1 -0
- package/dist/cli/introspection/resources.js +127 -0
- package/dist/cli/output/computedFields.d.ts +39 -0
- package/dist/cli/output/computedFields.js +104 -0
- package/dist/cli/output.d.ts +37 -0
- package/dist/cli/output.js +332 -0
- package/dist/cli/parse-command.d.ts +18 -0
- package/dist/cli/parse-command.js +109 -0
- package/dist/cli/router.d.ts +29 -0
- package/dist/cli/router.js +480 -0
- package/dist/cli/selection/buildAllSelection.d.ts +13 -0
- package/dist/cli/selection/buildAllSelection.js +108 -0
- package/dist/cli/selection/graphqlSelection.d.ts +5 -0
- package/dist/cli/selection/graphqlSelection.js +301 -0
- package/dist/cli/selection/select.d.ts +13 -0
- package/dist/cli/selection/select.js +136 -0
- package/dist/cli/selection/stripDeprecated.d.ts +2 -0
- package/dist/cli/selection/stripDeprecated.js +63 -0
- package/dist/cli/suggest.d.ts +5 -0
- package/dist/cli/suggest.js +88 -0
- package/dist/cli/userErrors.d.ts +4 -0
- package/dist/cli/userErrors.js +41 -0
- package/dist/cli/verbs/_shared.d.ts +38 -0
- package/dist/cli/verbs/_shared.js +181 -0
- package/dist/cli/verbs/abandoned-checkouts.d.ts +6 -0
- package/dist/cli/verbs/abandoned-checkouts.js +259 -0
- package/dist/cli/verbs/app-billing.d.ts +6 -0
- package/dist/cli/verbs/app-billing.js +452 -0
- package/dist/cli/verbs/apps.d.ts +6 -0
- package/dist/cli/verbs/apps.js +296 -0
- package/dist/cli/verbs/articles.d.ts +6 -0
- package/dist/cli/verbs/articles.js +251 -0
- package/dist/cli/verbs/backup.d.ts +6 -0
- package/dist/cli/verbs/backup.js +94 -0
- package/dist/cli/verbs/blogs.d.ts +6 -0
- package/dist/cli/verbs/blogs.js +273 -0
- package/dist/cli/verbs/bulk-operations.d.ts +6 -0
- package/dist/cli/verbs/bulk-operations.js +272 -0
- package/dist/cli/verbs/business-entities.d.ts +6 -0
- package/dist/cli/verbs/business-entities.js +102 -0
- package/dist/cli/verbs/carrier-services.d.ts +6 -0
- package/dist/cli/verbs/carrier-services.js +195 -0
- package/dist/cli/verbs/cart-transforms.d.ts +6 -0
- package/dist/cli/verbs/cart-transforms.js +141 -0
- package/dist/cli/verbs/cash-tracking.d.ts +6 -0
- package/dist/cli/verbs/cash-tracking.js +118 -0
- package/dist/cli/verbs/catalogs.d.ts +6 -0
- package/dist/cli/verbs/catalogs.js +267 -0
- package/dist/cli/verbs/channels.d.ts +6 -0
- package/dist/cli/verbs/channels.js +120 -0
- package/dist/cli/verbs/checkout-branding.d.ts +6 -0
- package/dist/cli/verbs/checkout-branding.js +144 -0
- package/dist/cli/verbs/checkout-profiles.d.ts +6 -0
- package/dist/cli/verbs/checkout-profiles.js +124 -0
- package/dist/cli/verbs/collections.d.ts +6 -0
- package/dist/cli/verbs/collections.js +620 -0
- package/dist/cli/verbs/comments.d.ts +6 -0
- package/dist/cli/verbs/comments.js +160 -0
- package/dist/cli/verbs/companies.d.ts +6 -0
- package/dist/cli/verbs/companies.js +313 -0
- package/dist/cli/verbs/company-contacts.d.ts +6 -0
- package/dist/cli/verbs/company-contacts.js +318 -0
- package/dist/cli/verbs/company-locations.d.ts +6 -0
- package/dist/cli/verbs/company-locations.js +467 -0
- package/dist/cli/verbs/customer-account-pages.d.ts +6 -0
- package/dist/cli/verbs/customer-account-pages.js +97 -0
- package/dist/cli/verbs/customer-payment-methods.d.ts +6 -0
- package/dist/cli/verbs/customer-payment-methods.js +358 -0
- package/dist/cli/verbs/customer-privacy.d.ts +6 -0
- package/dist/cli/verbs/customer-privacy.js +167 -0
- package/dist/cli/verbs/customer-segments.d.ts +6 -0
- package/dist/cli/verbs/customer-segments.js +193 -0
- package/dist/cli/verbs/customers.d.ts +6 -0
- package/dist/cli/verbs/customers.js +793 -0
- package/dist/cli/verbs/delegate-tokens.d.ts +6 -0
- package/dist/cli/verbs/delegate-tokens.js +95 -0
- package/dist/cli/verbs/delivery-customizations.d.ts +6 -0
- package/dist/cli/verbs/delivery-customizations.js +205 -0
- package/dist/cli/verbs/delivery-profile-locations.d.ts +6 -0
- package/dist/cli/verbs/delivery-profile-locations.js +90 -0
- package/dist/cli/verbs/delivery-profiles.d.ts +6 -0
- package/dist/cli/verbs/delivery-profiles.js +207 -0
- package/dist/cli/verbs/delivery-promises.d.ts +6 -0
- package/dist/cli/verbs/delivery-promises.js +262 -0
- package/dist/cli/verbs/delivery-settings.d.ts +6 -0
- package/dist/cli/verbs/delivery-settings.js +85 -0
- package/dist/cli/verbs/discount-nodes.d.ts +6 -0
- package/dist/cli/verbs/discount-nodes.js +169 -0
- package/dist/cli/verbs/discount-redeem-codes.d.ts +6 -0
- package/dist/cli/verbs/discount-redeem-codes.js +102 -0
- package/dist/cli/verbs/discount-saved-searches.d.ts +6 -0
- package/dist/cli/verbs/discount-saved-searches.js +113 -0
- package/dist/cli/verbs/discounts-automatic.d.ts +6 -0
- package/dist/cli/verbs/discounts-automatic.js +501 -0
- package/dist/cli/verbs/discounts-code.d.ts +6 -0
- package/dist/cli/verbs/discounts-code.js +540 -0
- package/dist/cli/verbs/disputes.d.ts +6 -0
- package/dist/cli/verbs/disputes.js +154 -0
- package/dist/cli/verbs/draft-orders.d.ts +6 -0
- package/dist/cli/verbs/draft-orders.js +475 -0
- package/dist/cli/verbs/events.d.ts +6 -0
- package/dist/cli/verbs/events.js +182 -0
- package/dist/cli/verbs/file-saved-searches.d.ts +6 -0
- package/dist/cli/verbs/file-saved-searches.js +83 -0
- package/dist/cli/verbs/files.d.ts +6 -0
- package/dist/cli/verbs/files.js +329 -0
- package/dist/cli/verbs/finance.d.ts +6 -0
- package/dist/cli/verbs/finance.js +115 -0
- package/dist/cli/verbs/flow.d.ts +6 -0
- package/dist/cli/verbs/flow.js +94 -0
- package/dist/cli/verbs/fulfillment-constraint-rules.d.ts +6 -0
- package/dist/cli/verbs/fulfillment-constraint-rules.js +139 -0
- package/dist/cli/verbs/fulfillment-orders.d.ts +6 -0
- package/dist/cli/verbs/fulfillment-orders.js +689 -0
- package/dist/cli/verbs/fulfillment-services.d.ts +6 -0
- package/dist/cli/verbs/fulfillment-services.js +212 -0
- package/dist/cli/verbs/fulfillments.d.ts +6 -0
- package/dist/cli/verbs/fulfillments.js +279 -0
- package/dist/cli/verbs/gift-cards.d.ts +6 -0
- package/dist/cli/verbs/gift-cards.js +359 -0
- package/dist/cli/verbs/graphql.d.ts +14 -0
- package/dist/cli/verbs/graphql.js +285 -0
- package/dist/cli/verbs/inventory-items.d.ts +6 -0
- package/dist/cli/verbs/inventory-items.js +164 -0
- package/dist/cli/verbs/inventory-shipments.d.ts +6 -0
- package/dist/cli/verbs/inventory-shipments.js +276 -0
- package/dist/cli/verbs/inventory-transfers.d.ts +6 -0
- package/dist/cli/verbs/inventory-transfers.js +396 -0
- package/dist/cli/verbs/inventory.d.ts +6 -0
- package/dist/cli/verbs/inventory.js +557 -0
- package/dist/cli/verbs/locales.d.ts +6 -0
- package/dist/cli/verbs/locales.js +61 -0
- package/dist/cli/verbs/locations.d.ts +6 -0
- package/dist/cli/verbs/locations.js +385 -0
- package/dist/cli/verbs/market-localizations.d.ts +6 -0
- package/dist/cli/verbs/market-localizations.js +291 -0
- package/dist/cli/verbs/market-web-presences.d.ts +6 -0
- package/dist/cli/verbs/market-web-presences.js +139 -0
- package/dist/cli/verbs/marketing-activities.d.ts +6 -0
- package/dist/cli/verbs/marketing-activities.js +353 -0
- package/dist/cli/verbs/marketing-events.d.ts +6 -0
- package/dist/cli/verbs/marketing-events.js +132 -0
- package/dist/cli/verbs/markets.d.ts +6 -0
- package/dist/cli/verbs/markets.js +357 -0
- package/dist/cli/verbs/menus.d.ts +6 -0
- package/dist/cli/verbs/menus.js +251 -0
- package/dist/cli/verbs/metafield-definition-tools.d.ts +6 -0
- package/dist/cli/verbs/metafield-definition-tools.js +289 -0
- package/dist/cli/verbs/metafield-definitions.d.ts +6 -0
- package/dist/cli/verbs/metafield-definitions.js +240 -0
- package/dist/cli/verbs/metafields.d.ts +6 -0
- package/dist/cli/verbs/metafields.js +112 -0
- package/dist/cli/verbs/metaobject-definition-tools.d.ts +6 -0
- package/dist/cli/verbs/metaobject-definition-tools.js +83 -0
- package/dist/cli/verbs/metaobject-definitions.d.ts +6 -0
- package/dist/cli/verbs/metaobject-definitions.js +176 -0
- package/dist/cli/verbs/metaobjects.d.ts +6 -0
- package/dist/cli/verbs/metaobjects.js +306 -0
- package/dist/cli/verbs/mobile-platform-applications.d.ts +6 -0
- package/dist/cli/verbs/mobile-platform-applications.js +247 -0
- package/dist/cli/verbs/order-edit.d.ts +6 -0
- package/dist/cli/verbs/order-edit.js +596 -0
- package/dist/cli/verbs/orders.d.ts +6 -0
- package/dist/cli/verbs/orders.js +853 -0
- package/dist/cli/verbs/pages.d.ts +6 -0
- package/dist/cli/verbs/pages.js +234 -0
- package/dist/cli/verbs/payment-customizations.d.ts +6 -0
- package/dist/cli/verbs/payment-customizations.js +193 -0
- package/dist/cli/verbs/payment-terms.d.ts +6 -0
- package/dist/cli/verbs/payment-terms.js +228 -0
- package/dist/cli/verbs/point-of-sale.d.ts +6 -0
- package/dist/cli/verbs/point-of-sale.js +57 -0
- package/dist/cli/verbs/price-lists.d.ts +6 -0
- package/dist/cli/verbs/price-lists.js +426 -0
- package/dist/cli/verbs/product-feeds.d.ts +6 -0
- package/dist/cli/verbs/product-feeds.js +187 -0
- package/dist/cli/verbs/product-variants.d.ts +6 -0
- package/dist/cli/verbs/product-variants.js +439 -0
- package/dist/cli/verbs/products.d.ts +6 -0
- package/dist/cli/verbs/products.js +2309 -0
- package/dist/cli/verbs/publications.d.ts +6 -0
- package/dist/cli/verbs/publications.js +256 -0
- package/dist/cli/verbs/publishables.d.ts +6 -0
- package/dist/cli/verbs/publishables.js +73 -0
- package/dist/cli/verbs/refunds.d.ts +6 -0
- package/dist/cli/verbs/refunds.js +226 -0
- package/dist/cli/verbs/resource-feedback.d.ts +6 -0
- package/dist/cli/verbs/resource-feedback.js +119 -0
- package/dist/cli/verbs/returnable-fulfillments.d.ts +6 -0
- package/dist/cli/verbs/returnable-fulfillments.js +102 -0
- package/dist/cli/verbs/returns.d.ts +6 -0
- package/dist/cli/verbs/returns.js +506 -0
- package/dist/cli/verbs/reverse-deliveries.d.ts +6 -0
- package/dist/cli/verbs/reverse-deliveries.js +203 -0
- package/dist/cli/verbs/reverse-fulfillment-orders.d.ts +6 -0
- package/dist/cli/verbs/reverse-fulfillment-orders.js +157 -0
- package/dist/cli/verbs/saved-searches.d.ts +6 -0
- package/dist/cli/verbs/saved-searches.js +150 -0
- package/dist/cli/verbs/script-tags.d.ts +6 -0
- package/dist/cli/verbs/script-tags.js +179 -0
- package/dist/cli/verbs/segments.d.ts +6 -0
- package/dist/cli/verbs/segments.js +343 -0
- package/dist/cli/verbs/selling-plan-group-products.d.ts +6 -0
- package/dist/cli/verbs/selling-plan-group-products.js +115 -0
- package/dist/cli/verbs/selling-plan-groups.d.ts +6 -0
- package/dist/cli/verbs/selling-plan-groups.js +230 -0
- package/dist/cli/verbs/server-pixels.d.ts +6 -0
- package/dist/cli/verbs/server-pixels.js +172 -0
- package/dist/cli/verbs/shipping-packages.d.ts +6 -0
- package/dist/cli/verbs/shipping-packages.js +107 -0
- package/dist/cli/verbs/shop-policies.d.ts +6 -0
- package/dist/cli/verbs/shop-policies.js +91 -0
- package/dist/cli/verbs/shop-utils.d.ts +6 -0
- package/dist/cli/verbs/shop-utils.js +147 -0
- package/dist/cli/verbs/shop.d.ts +6 -0
- package/dist/cli/verbs/shop.js +177 -0
- package/dist/cli/verbs/shopify-functions.d.ts +6 -0
- package/dist/cli/verbs/shopify-functions.js +127 -0
- package/dist/cli/verbs/shopify-payments.d.ts +6 -0
- package/dist/cli/verbs/shopify-payments.js +111 -0
- package/dist/cli/verbs/staff.d.ts +6 -0
- package/dist/cli/verbs/staff.js +127 -0
- package/dist/cli/verbs/staged-uploads.d.ts +6 -0
- package/dist/cli/verbs/staged-uploads.js +128 -0
- package/dist/cli/verbs/store-credit.d.ts +6 -0
- package/dist/cli/verbs/store-credit.js +209 -0
- package/dist/cli/verbs/storefront-access-tokens.d.ts +6 -0
- package/dist/cli/verbs/storefront-access-tokens.js +183 -0
- package/dist/cli/verbs/subscription-billing-cycles.d.ts +6 -0
- package/dist/cli/verbs/subscription-billing-cycles.js +391 -0
- package/dist/cli/verbs/subscription-billing.d.ts +6 -0
- package/dist/cli/verbs/subscription-billing.js +391 -0
- package/dist/cli/verbs/subscription-contracts.d.ts +6 -0
- package/dist/cli/verbs/subscription-contracts.js +392 -0
- package/dist/cli/verbs/subscription-drafts.d.ts +6 -0
- package/dist/cli/verbs/subscription-drafts.js +315 -0
- package/dist/cli/verbs/tags.d.ts +6 -0
- package/dist/cli/verbs/tags.js +73 -0
- package/dist/cli/verbs/tax.d.ts +6 -0
- package/dist/cli/verbs/tax.js +114 -0
- package/dist/cli/verbs/taxonomy.d.ts +6 -0
- package/dist/cli/verbs/taxonomy.js +99 -0
- package/dist/cli/verbs/tender-transactions.d.ts +6 -0
- package/dist/cli/verbs/tender-transactions.js +105 -0
- package/dist/cli/verbs/themes.d.ts +6 -0
- package/dist/cli/verbs/themes.js +315 -0
- package/dist/cli/verbs/translations.d.ts +6 -0
- package/dist/cli/verbs/translations.js +221 -0
- package/dist/cli/verbs/types.d.ts +4 -0
- package/dist/cli/verbs/types.js +224 -0
- package/dist/cli/verbs/url-redirects.d.ts +6 -0
- package/dist/cli/verbs/url-redirects.js +465 -0
- package/dist/cli/verbs/validations.d.ts +6 -0
- package/dist/cli/verbs/validations.js +181 -0
- package/dist/cli/verbs/web-pixels.d.ts +6 -0
- package/dist/cli/verbs/web-pixels.js +145 -0
- package/dist/cli/verbs/web-presences.d.ts +6 -0
- package/dist/cli/verbs/web-presences.js +186 -0
- package/dist/cli/verbs/webhooks.d.ts +6 -0
- package/dist/cli/verbs/webhooks.js +336 -0
- package/dist/cli/workflows/files/stagedUploads.d.ts +28 -0
- package/dist/cli/workflows/files/stagedUploads.js +227 -0
- package/dist/cli/workflows/files/stdinFile.d.ts +7 -0
- package/dist/cli/workflows/files/stdinFile.js +65 -0
- package/dist/cli/workflows/files/urlDownloads.d.ts +14 -0
- package/dist/cli/workflows/files/urlDownloads.js +114 -0
- package/dist/cli/workflows/files/waitForReady.d.ts +20 -0
- package/dist/cli/workflows/files/waitForReady.js +114 -0
- package/dist/cli/workflows/inventory/resolveInventoryItemId.d.ts +6 -0
- package/dist/cli/workflows/inventory/resolveInventoryItemId.js +59 -0
- package/dist/cli/workflows/productVariants/upsert.d.ts +8 -0
- package/dist/cli/workflows/productVariants/upsert.js +110 -0
- package/dist/cli/workflows/products/metafieldsUpsert.d.ts +6 -0
- package/dist/cli/workflows/products/metafieldsUpsert.js +94 -0
- package/dist/cli/workflows/products/publishablePublish.d.ts +21 -0
- package/dist/cli/workflows/products/publishablePublish.js +131 -0
- package/dist/cli/workflows/publications/resolvePublicationId.d.ts +17 -0
- package/dist/cli/workflows/publications/resolvePublicationId.js +93 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +238 -0
- package/dist/defaults.d.ts +2 -0
- package/dist/defaults.js +38 -0
- package/dist/generated/admin-2026-04/index.d.ts +25 -0
- package/dist/generated/admin-2026-04/index.js +70 -0
- package/dist/generated/admin-2026-04/runtime/batcher.d.ts +105 -0
- package/dist/generated/admin-2026-04/runtime/batcher.js +203 -0
- package/dist/generated/admin-2026-04/runtime/createClient.d.ts +17 -0
- package/dist/generated/admin-2026-04/runtime/createClient.js +59 -0
- package/dist/generated/admin-2026-04/runtime/error.d.ts +18 -0
- package/dist/generated/admin-2026-04/runtime/error.js +44 -0
- package/dist/generated/admin-2026-04/runtime/fetcher.d.ts +10 -0
- package/dist/generated/admin-2026-04/runtime/fetcher.js +104 -0
- package/dist/generated/admin-2026-04/runtime/generateGraphqlOperation.d.ts +30 -0
- package/dist/generated/admin-2026-04/runtime/generateGraphqlOperation.js +191 -0
- package/dist/generated/admin-2026-04/runtime/index.d.ts +11 -0
- package/dist/generated/admin-2026-04/runtime/index.js +46 -0
- package/dist/generated/admin-2026-04/runtime/linkTypeMap.d.ts +9 -0
- package/dist/generated/admin-2026-04/runtime/linkTypeMap.js +142 -0
- package/dist/generated/admin-2026-04/runtime/typeSelection.d.ts +28 -0
- package/dist/generated/admin-2026-04/runtime/typeSelection.js +17 -0
- package/dist/generated/admin-2026-04/runtime/types.d.ts +55 -0
- package/dist/generated/admin-2026-04/runtime/types.js +17 -0
- package/dist/generated/admin-2026-04/schema.d.ts +102240 -0
- package/dist/generated/admin-2026-04/schema.graphql +91596 -0
- package/dist/generated/admin-2026-04/schema.js +20322 -0
- package/dist/generated/admin-2026-04/types.d.ts +24224 -0
- package/dist/generated/admin-2026-04/types.js +62299 -0
- package/dist/generated/help/schema-help.d.ts +30 -0
- package/dist/generated/help/schema-help.js +61833 -0
- package/dist/graphqlValidator.d.ts +17 -0
- package/dist/graphqlValidator.js +84 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +23 -0
- package/package.json +66 -0
- package/schema/2026-04.graphql +61256 -0
- package/schema/2026-04.introspection.json +1 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { GraphqlOperation } from './generateGraphqlOperation';
|
|
2
|
+
type Variables = Record<string, any>;
|
|
3
|
+
type QueryError = Error & {
|
|
4
|
+
message: string;
|
|
5
|
+
locations?: Array<{
|
|
6
|
+
line: number;
|
|
7
|
+
column: number;
|
|
8
|
+
}>;
|
|
9
|
+
path?: any;
|
|
10
|
+
rid: string;
|
|
11
|
+
details?: Record<string, any>;
|
|
12
|
+
};
|
|
13
|
+
type Result = {
|
|
14
|
+
data: Record<string, any>;
|
|
15
|
+
errors: Array<QueryError>;
|
|
16
|
+
};
|
|
17
|
+
type Fetcher = (batchedQuery: GraphqlOperation | Array<GraphqlOperation>) => Promise<Array<Result>>;
|
|
18
|
+
type Options = {
|
|
19
|
+
batchInterval?: number;
|
|
20
|
+
shouldBatch?: boolean;
|
|
21
|
+
maxBatchSize?: number;
|
|
22
|
+
};
|
|
23
|
+
type Queue = Array<{
|
|
24
|
+
request: GraphqlOperation;
|
|
25
|
+
resolve: (...args: Array<any>) => any;
|
|
26
|
+
reject: (...args: Array<any>) => any;
|
|
27
|
+
}>;
|
|
28
|
+
/**
|
|
29
|
+
* Create a batcher client.
|
|
30
|
+
* @param {Fetcher} fetcher - A function that can handle the network requests to graphql endpoint
|
|
31
|
+
* @param {Options} options - the options to be used by client
|
|
32
|
+
* @param {boolean} options.shouldBatch - should the client batch requests. (default true)
|
|
33
|
+
* @param {integer} options.batchInterval - duration (in MS) of each batch window. (default 6)
|
|
34
|
+
* @param {integer} options.maxBatchSize - max number of requests in a batch. (default 0)
|
|
35
|
+
* @param {boolean} options.defaultHeaders - default headers to include with every request
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* const fetcher = batchedQuery => fetch('path/to/graphql', {
|
|
39
|
+
* method: 'post',
|
|
40
|
+
* headers: {
|
|
41
|
+
* Accept: 'application/json',
|
|
42
|
+
* 'Content-Type': 'application/json',
|
|
43
|
+
* },
|
|
44
|
+
* body: JSON.stringify(batchedQuery),
|
|
45
|
+
* credentials: 'include',
|
|
46
|
+
* })
|
|
47
|
+
* .then(response => response.json())
|
|
48
|
+
*
|
|
49
|
+
* const client = new QueryBatcher(fetcher, { maxBatchSize: 10 })
|
|
50
|
+
*/
|
|
51
|
+
export declare class QueryBatcher {
|
|
52
|
+
fetcher: Fetcher;
|
|
53
|
+
_options: Options;
|
|
54
|
+
_queue: Queue;
|
|
55
|
+
constructor(fetcher: Fetcher, { batchInterval, shouldBatch, maxBatchSize, }?: Options);
|
|
56
|
+
/**
|
|
57
|
+
* Fetch will send a graphql request and return the parsed json.
|
|
58
|
+
* @param {string} query - the graphql query.
|
|
59
|
+
* @param {Variables} variables - any variables you wish to inject as key/value pairs.
|
|
60
|
+
* @param {[string]} operationName - the graphql operationName.
|
|
61
|
+
* @param {Options} overrides - the client options overrides.
|
|
62
|
+
*
|
|
63
|
+
* @return {promise} resolves to parsed json of server response
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* client.fetch(`
|
|
67
|
+
* query getHuman($id: ID!) {
|
|
68
|
+
* human(id: $id) {
|
|
69
|
+
* name
|
|
70
|
+
* height
|
|
71
|
+
* }
|
|
72
|
+
* }
|
|
73
|
+
* `, { id: "1001" }, 'getHuman')
|
|
74
|
+
* .then(human => {
|
|
75
|
+
* // do something with human
|
|
76
|
+
* console.log(human);
|
|
77
|
+
* });
|
|
78
|
+
*/
|
|
79
|
+
fetch(query: string, variables?: Variables, operationName?: string, overrides?: Options): Promise<Result>;
|
|
80
|
+
/**
|
|
81
|
+
* Fetch will send a graphql request and return the parsed json.
|
|
82
|
+
* @param {string} query - the graphql query.
|
|
83
|
+
* @param {Variables} variables - any variables you wish to inject as key/value pairs.
|
|
84
|
+
* @param {[string]} operationName - the graphql operationName.
|
|
85
|
+
* @param {Options} overrides - the client options overrides.
|
|
86
|
+
*
|
|
87
|
+
* @return {Promise<Array<Result>>} resolves to parsed json of server response
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* client.forceFetch(`
|
|
91
|
+
* query getHuman($id: ID!) {
|
|
92
|
+
* human(id: $id) {
|
|
93
|
+
* name
|
|
94
|
+
* height
|
|
95
|
+
* }
|
|
96
|
+
* }
|
|
97
|
+
* `, { id: "1001" }, 'getHuman')
|
|
98
|
+
* .then(human => {
|
|
99
|
+
* // do something with human
|
|
100
|
+
* console.log(human);
|
|
101
|
+
* });
|
|
102
|
+
*/
|
|
103
|
+
forceFetch(query: string, variables?: Variables, operationName?: string, overrides?: Options): Promise<Result>;
|
|
104
|
+
}
|
|
105
|
+
export {};
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var batcher_exports = {};
|
|
20
|
+
__export(batcher_exports, {
|
|
21
|
+
QueryBatcher: () => QueryBatcher
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(batcher_exports);
|
|
24
|
+
var import_error = require("./error");
|
|
25
|
+
function dispatchQueueBatch(client, queue) {
|
|
26
|
+
let batchedQuery = queue.map((item) => item.request);
|
|
27
|
+
if (batchedQuery.length === 1) {
|
|
28
|
+
batchedQuery = batchedQuery[0];
|
|
29
|
+
}
|
|
30
|
+
(() => {
|
|
31
|
+
try {
|
|
32
|
+
return client.fetcher(batchedQuery);
|
|
33
|
+
} catch (e) {
|
|
34
|
+
return Promise.reject(e);
|
|
35
|
+
}
|
|
36
|
+
})().then((responses) => {
|
|
37
|
+
if (queue.length === 1 && !Array.isArray(responses)) {
|
|
38
|
+
if (responses.errors && responses.errors.length) {
|
|
39
|
+
queue[0].reject(
|
|
40
|
+
new import_error.GenqlError(responses.errors, responses.data)
|
|
41
|
+
);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
queue[0].resolve(responses);
|
|
45
|
+
return;
|
|
46
|
+
} else if (responses.length !== queue.length) {
|
|
47
|
+
throw new Error("response length did not match query length");
|
|
48
|
+
}
|
|
49
|
+
for (let i = 0; i < queue.length; i++) {
|
|
50
|
+
if (responses[i].errors && responses[i].errors.length) {
|
|
51
|
+
queue[i].reject(
|
|
52
|
+
new import_error.GenqlError(responses[i].errors, responses[i].data)
|
|
53
|
+
);
|
|
54
|
+
} else {
|
|
55
|
+
queue[i].resolve(responses[i]);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}).catch((e) => {
|
|
59
|
+
for (let i = 0; i < queue.length; i++) {
|
|
60
|
+
queue[i].reject(e);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
function dispatchQueue(client, options) {
|
|
65
|
+
const queue = client._queue;
|
|
66
|
+
const maxBatchSize = options.maxBatchSize || 0;
|
|
67
|
+
client._queue = [];
|
|
68
|
+
if (maxBatchSize > 0 && maxBatchSize < queue.length) {
|
|
69
|
+
for (let i = 0; i < queue.length / maxBatchSize; i++) {
|
|
70
|
+
dispatchQueueBatch(
|
|
71
|
+
client,
|
|
72
|
+
queue.slice(i * maxBatchSize, (i + 1) * maxBatchSize)
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
} else {
|
|
76
|
+
dispatchQueueBatch(client, queue);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
class QueryBatcher {
|
|
80
|
+
fetcher;
|
|
81
|
+
_options;
|
|
82
|
+
_queue;
|
|
83
|
+
constructor(fetcher, {
|
|
84
|
+
batchInterval = 6,
|
|
85
|
+
shouldBatch = true,
|
|
86
|
+
maxBatchSize = 0
|
|
87
|
+
} = {}) {
|
|
88
|
+
this.fetcher = fetcher;
|
|
89
|
+
this._options = {
|
|
90
|
+
batchInterval,
|
|
91
|
+
shouldBatch,
|
|
92
|
+
maxBatchSize
|
|
93
|
+
};
|
|
94
|
+
this._queue = [];
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Fetch will send a graphql request and return the parsed json.
|
|
98
|
+
* @param {string} query - the graphql query.
|
|
99
|
+
* @param {Variables} variables - any variables you wish to inject as key/value pairs.
|
|
100
|
+
* @param {[string]} operationName - the graphql operationName.
|
|
101
|
+
* @param {Options} overrides - the client options overrides.
|
|
102
|
+
*
|
|
103
|
+
* @return {promise} resolves to parsed json of server response
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* client.fetch(`
|
|
107
|
+
* query getHuman($id: ID!) {
|
|
108
|
+
* human(id: $id) {
|
|
109
|
+
* name
|
|
110
|
+
* height
|
|
111
|
+
* }
|
|
112
|
+
* }
|
|
113
|
+
* `, { id: "1001" }, 'getHuman')
|
|
114
|
+
* .then(human => {
|
|
115
|
+
* // do something with human
|
|
116
|
+
* console.log(human);
|
|
117
|
+
* });
|
|
118
|
+
*/
|
|
119
|
+
fetch(query, variables, operationName, overrides = {}) {
|
|
120
|
+
const request = {
|
|
121
|
+
query
|
|
122
|
+
};
|
|
123
|
+
const options = Object.assign({}, this._options, overrides);
|
|
124
|
+
if (variables) {
|
|
125
|
+
request.variables = variables;
|
|
126
|
+
}
|
|
127
|
+
if (operationName) {
|
|
128
|
+
request.operationName = operationName;
|
|
129
|
+
}
|
|
130
|
+
const promise = new Promise((resolve, reject) => {
|
|
131
|
+
this._queue.push({
|
|
132
|
+
request,
|
|
133
|
+
resolve,
|
|
134
|
+
reject
|
|
135
|
+
});
|
|
136
|
+
if (this._queue.length === 1) {
|
|
137
|
+
if (options.shouldBatch) {
|
|
138
|
+
setTimeout(
|
|
139
|
+
() => dispatchQueue(this, options),
|
|
140
|
+
options.batchInterval
|
|
141
|
+
);
|
|
142
|
+
} else {
|
|
143
|
+
dispatchQueue(this, options);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
return promise;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Fetch will send a graphql request and return the parsed json.
|
|
151
|
+
* @param {string} query - the graphql query.
|
|
152
|
+
* @param {Variables} variables - any variables you wish to inject as key/value pairs.
|
|
153
|
+
* @param {[string]} operationName - the graphql operationName.
|
|
154
|
+
* @param {Options} overrides - the client options overrides.
|
|
155
|
+
*
|
|
156
|
+
* @return {Promise<Array<Result>>} resolves to parsed json of server response
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* client.forceFetch(`
|
|
160
|
+
* query getHuman($id: ID!) {
|
|
161
|
+
* human(id: $id) {
|
|
162
|
+
* name
|
|
163
|
+
* height
|
|
164
|
+
* }
|
|
165
|
+
* }
|
|
166
|
+
* `, { id: "1001" }, 'getHuman')
|
|
167
|
+
* .then(human => {
|
|
168
|
+
* // do something with human
|
|
169
|
+
* console.log(human);
|
|
170
|
+
* });
|
|
171
|
+
*/
|
|
172
|
+
forceFetch(query, variables, operationName, overrides = {}) {
|
|
173
|
+
const request = {
|
|
174
|
+
query
|
|
175
|
+
};
|
|
176
|
+
const options = Object.assign({}, this._options, overrides, {
|
|
177
|
+
shouldBatch: false
|
|
178
|
+
});
|
|
179
|
+
if (variables) {
|
|
180
|
+
request.variables = variables;
|
|
181
|
+
}
|
|
182
|
+
if (operationName) {
|
|
183
|
+
request.operationName = operationName;
|
|
184
|
+
}
|
|
185
|
+
const promise = new Promise((resolve, reject) => {
|
|
186
|
+
const client = new QueryBatcher(this.fetcher, this._options);
|
|
187
|
+
client._queue = [
|
|
188
|
+
{
|
|
189
|
+
request,
|
|
190
|
+
resolve,
|
|
191
|
+
reject
|
|
192
|
+
}
|
|
193
|
+
];
|
|
194
|
+
dispatchQueue(client, options);
|
|
195
|
+
});
|
|
196
|
+
return promise;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
200
|
+
0 && (module.exports = {
|
|
201
|
+
QueryBatcher
|
|
202
|
+
});
|
|
203
|
+
//# sourceMappingURL=batcher.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type BatchOptions } from './fetcher';
|
|
2
|
+
import type { ExecutionResult, LinkedType } from './types';
|
|
3
|
+
import { type GraphqlOperation } from './generateGraphqlOperation';
|
|
4
|
+
export type Headers = HeadersInit | (() => HeadersInit) | (() => Promise<HeadersInit>);
|
|
5
|
+
export type BaseFetcher = (operation: GraphqlOperation | GraphqlOperation[]) => Promise<ExecutionResult | ExecutionResult[]>;
|
|
6
|
+
export type ClientOptions = Omit<RequestInit, 'body' | 'headers'> & {
|
|
7
|
+
url?: string;
|
|
8
|
+
batch?: BatchOptions | boolean;
|
|
9
|
+
fetcher?: BaseFetcher;
|
|
10
|
+
fetch?: Function;
|
|
11
|
+
headers?: Headers;
|
|
12
|
+
};
|
|
13
|
+
export declare const createClient: ({ queryRoot, mutationRoot, subscriptionRoot, ...options }: ClientOptions & {
|
|
14
|
+
queryRoot?: LinkedType;
|
|
15
|
+
mutationRoot?: LinkedType;
|
|
16
|
+
subscriptionRoot?: LinkedType;
|
|
17
|
+
}) => any;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var createClient_exports = {};
|
|
20
|
+
__export(createClient_exports, {
|
|
21
|
+
createClient: () => createClient
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(createClient_exports);
|
|
24
|
+
var import_fetcher = require("./fetcher");
|
|
25
|
+
var import_generateGraphqlOperation = require("./generateGraphqlOperation");
|
|
26
|
+
const createClient = ({
|
|
27
|
+
queryRoot,
|
|
28
|
+
mutationRoot,
|
|
29
|
+
subscriptionRoot,
|
|
30
|
+
...options
|
|
31
|
+
}) => {
|
|
32
|
+
const fetcher = (0, import_fetcher.createFetcher)(options);
|
|
33
|
+
const client = {};
|
|
34
|
+
if (queryRoot) {
|
|
35
|
+
client.query = (request) => {
|
|
36
|
+
if (!queryRoot) throw new Error("queryRoot argument is missing");
|
|
37
|
+
const resultPromise = fetcher(
|
|
38
|
+
(0, import_generateGraphqlOperation.generateGraphqlOperation)("query", queryRoot, request)
|
|
39
|
+
);
|
|
40
|
+
return resultPromise;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
if (mutationRoot) {
|
|
44
|
+
client.mutation = (request) => {
|
|
45
|
+
if (!mutationRoot)
|
|
46
|
+
throw new Error("mutationRoot argument is missing");
|
|
47
|
+
const resultPromise = fetcher(
|
|
48
|
+
(0, import_generateGraphqlOperation.generateGraphqlOperation)("mutation", mutationRoot, request)
|
|
49
|
+
);
|
|
50
|
+
return resultPromise;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
return client;
|
|
54
|
+
};
|
|
55
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
56
|
+
0 && (module.exports = {
|
|
57
|
+
createClient
|
|
58
|
+
});
|
|
59
|
+
//# sourceMappingURL=createClient.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare class GenqlError extends Error {
|
|
2
|
+
errors: Array<GraphqlError>;
|
|
3
|
+
/**
|
|
4
|
+
* Partial data returned by the server
|
|
5
|
+
*/
|
|
6
|
+
data?: any;
|
|
7
|
+
constructor(errors: any[], data: any);
|
|
8
|
+
}
|
|
9
|
+
interface GraphqlError {
|
|
10
|
+
message: string;
|
|
11
|
+
locations?: Array<{
|
|
12
|
+
line: number;
|
|
13
|
+
column: number;
|
|
14
|
+
}>;
|
|
15
|
+
path?: string[];
|
|
16
|
+
extensions?: Record<string, any>;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var error_exports = {};
|
|
20
|
+
__export(error_exports, {
|
|
21
|
+
GenqlError: () => GenqlError
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(error_exports);
|
|
24
|
+
class GenqlError extends Error {
|
|
25
|
+
errors = [];
|
|
26
|
+
/**
|
|
27
|
+
* Partial data returned by the server
|
|
28
|
+
*/
|
|
29
|
+
data;
|
|
30
|
+
constructor(errors, data) {
|
|
31
|
+
let message = Array.isArray(errors) ? errors.map((x) => x?.message || "").join("\n") : "";
|
|
32
|
+
if (!message) {
|
|
33
|
+
message = "GraphQL error";
|
|
34
|
+
}
|
|
35
|
+
super(message);
|
|
36
|
+
this.errors = errors;
|
|
37
|
+
this.data = data;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
+
0 && (module.exports = {
|
|
42
|
+
GenqlError
|
|
43
|
+
});
|
|
44
|
+
//# sourceMappingURL=error.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ClientOptions } from './createClient';
|
|
2
|
+
import type { GraphqlOperation } from './generateGraphqlOperation';
|
|
3
|
+
export interface Fetcher {
|
|
4
|
+
(gql: GraphqlOperation): Promise<any>;
|
|
5
|
+
}
|
|
6
|
+
export type BatchOptions = {
|
|
7
|
+
batchInterval?: number;
|
|
8
|
+
maxBatchSize?: number;
|
|
9
|
+
};
|
|
10
|
+
export declare const createFetcher: ({ url, headers, fetcher, fetch: _fetch, batch, ...rest }: ClientOptions) => Fetcher;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var fetcher_exports = {};
|
|
20
|
+
__export(fetcher_exports, {
|
|
21
|
+
createFetcher: () => createFetcher
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(fetcher_exports);
|
|
24
|
+
var import_batcher = require("./batcher");
|
|
25
|
+
var import_error = require("./error");
|
|
26
|
+
const DEFAULT_BATCH_OPTIONS = {
|
|
27
|
+
maxBatchSize: 10,
|
|
28
|
+
batchInterval: 40
|
|
29
|
+
};
|
|
30
|
+
const createFetcher = ({
|
|
31
|
+
url,
|
|
32
|
+
headers = {},
|
|
33
|
+
fetcher,
|
|
34
|
+
fetch: _fetch,
|
|
35
|
+
batch = false,
|
|
36
|
+
...rest
|
|
37
|
+
}) => {
|
|
38
|
+
if (!url && !fetcher) {
|
|
39
|
+
throw new Error("url or fetcher is required");
|
|
40
|
+
}
|
|
41
|
+
fetcher = fetcher || (async (body) => {
|
|
42
|
+
let headersObject = typeof headers == "function" ? await headers() : headers;
|
|
43
|
+
headersObject = headersObject || {};
|
|
44
|
+
if (typeof fetch === "undefined" && !_fetch) {
|
|
45
|
+
throw new Error(
|
|
46
|
+
"Global `fetch` function is not available, pass a fetch polyfill to Genql `createClient`"
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
let fetchImpl = _fetch || fetch;
|
|
50
|
+
const res = await fetchImpl(url, {
|
|
51
|
+
headers: {
|
|
52
|
+
"Content-Type": "application/json",
|
|
53
|
+
...headersObject
|
|
54
|
+
},
|
|
55
|
+
method: "POST",
|
|
56
|
+
body: JSON.stringify(body),
|
|
57
|
+
...rest
|
|
58
|
+
});
|
|
59
|
+
if (!res.ok) {
|
|
60
|
+
throw new Error(`${res.statusText}: ${await res.text()}`);
|
|
61
|
+
}
|
|
62
|
+
const json = await res.json();
|
|
63
|
+
return json;
|
|
64
|
+
});
|
|
65
|
+
if (!batch) {
|
|
66
|
+
return async (body) => {
|
|
67
|
+
const json = await fetcher(body);
|
|
68
|
+
if (Array.isArray(json)) {
|
|
69
|
+
return json.map((json2) => {
|
|
70
|
+
if (json2?.errors?.length) {
|
|
71
|
+
throw new import_error.GenqlError(json2.errors || [], json2.data);
|
|
72
|
+
}
|
|
73
|
+
return json2.data;
|
|
74
|
+
});
|
|
75
|
+
} else {
|
|
76
|
+
if (json?.errors?.length) {
|
|
77
|
+
throw new import_error.GenqlError(json.errors || [], json.data);
|
|
78
|
+
}
|
|
79
|
+
return json.data;
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
const batcher = new import_batcher.QueryBatcher(
|
|
84
|
+
async (batchedQuery) => {
|
|
85
|
+
const json = await fetcher(batchedQuery);
|
|
86
|
+
return json;
|
|
87
|
+
},
|
|
88
|
+
batch === true ? DEFAULT_BATCH_OPTIONS : batch
|
|
89
|
+
);
|
|
90
|
+
return async ({ query, variables }) => {
|
|
91
|
+
const json = await batcher.fetch(query, variables);
|
|
92
|
+
if (json?.data) {
|
|
93
|
+
return json.data;
|
|
94
|
+
}
|
|
95
|
+
throw new Error(
|
|
96
|
+
"Genql batch fetcher returned unexpected result " + JSON.stringify(json)
|
|
97
|
+
);
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
101
|
+
0 && (module.exports = {
|
|
102
|
+
createFetcher
|
|
103
|
+
});
|
|
104
|
+
//# sourceMappingURL=fetcher.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { LinkedField, LinkedType } from './types';
|
|
2
|
+
export interface Args {
|
|
3
|
+
[arg: string]: any | undefined;
|
|
4
|
+
}
|
|
5
|
+
export interface Fields {
|
|
6
|
+
[field: string]: Request;
|
|
7
|
+
}
|
|
8
|
+
export type Request = boolean | number | Fields;
|
|
9
|
+
export interface Variables {
|
|
10
|
+
[name: string]: {
|
|
11
|
+
value: any;
|
|
12
|
+
typing: [LinkedType, string];
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export interface Context {
|
|
16
|
+
root: LinkedType;
|
|
17
|
+
varCounter: number;
|
|
18
|
+
variables: Variables;
|
|
19
|
+
fragmentCounter: number;
|
|
20
|
+
fragments: string[];
|
|
21
|
+
}
|
|
22
|
+
export interface GraphqlOperation {
|
|
23
|
+
query: string;
|
|
24
|
+
variables?: {
|
|
25
|
+
[name: string]: any;
|
|
26
|
+
};
|
|
27
|
+
operationName?: string;
|
|
28
|
+
}
|
|
29
|
+
export declare const generateGraphqlOperation: (operation: "query" | "mutation" | "subscription", root: LinkedType, fields?: Fields) => GraphqlOperation;
|
|
30
|
+
export declare const getFieldFromPath: (root: LinkedType | undefined, path: string[]) => LinkedField;
|