diff --git a/graphql/directives.graphql b/graphql/directives.graphql index d1c2db74..e882ede5 100644 --- a/graphql/directives.graphql +++ b/graphql/directives.graphql @@ -1,3 +1,5 @@ directive @withSegment on FIELD_DEFINITION -directive @withOrderFormId on FIELD_DEFINITION \ No newline at end of file +directive @withOrderFormId on FIELD_DEFINITION + +directive @noCache on FIELD_DEFINITION \ No newline at end of file diff --git a/graphql/schema.graphql b/graphql/schema.graphql index 39a918e3..15f3b299 100644 --- a/graphql/schema.graphql +++ b/graphql/schema.graphql @@ -1,11 +1,11 @@ type Query { getCardSessionId: String orderForm(orderFormId: ID, refreshOutdatedData: Boolean): OrderForm! - @cacheControl(maxAge: ZERO, scope: PRIVATE) + @noCache @withOrderFormId @withSegment checkoutProfile(email: String!): CheckoutProfile - @cacheControl(maxAge: ZERO, scope: PRIVATE) + @noCache shippingSLA( items: [ShippingItem] postalCode: String @@ -23,88 +23,88 @@ type Mutation { marketingData: MarketingDataInput salesChannel: String allowedOutdatedData: [String!] - ): OrderForm! @withOrderFormId @withSegment + ): OrderForm! @withOrderFormId @withSegment @noCache updateItems( orderFormId: ID orderItems: [ItemInput] splitItem: Boolean = true allowedOutdatedData: [String!] - ): OrderForm! @withOrderFormId + ): OrderForm! @withOrderFormId @noCache addItemOffering(orderFormId: ID, offeringInput: OfferingInput): OrderForm! - @withOrderFormId + @withOrderFormId @noCache removeItemOffering(orderFormId: ID, offeringInput: OfferingInput): OrderForm! - @withOrderFormId + @withOrderFormId @noCache addBundleItemAttachment( orderFormId: ID bundleItemAttachmentInput: BundleItemAttachmentInput - ): OrderForm! @withOrderFormId + ): OrderForm! @withOrderFormId @noCache removeBundleItemAttachment( orderFormId: ID bundleItemAttachmentInput: BundleItemAttachmentInput - ): OrderForm! @withOrderFormId + ): OrderForm! @withOrderFormId @noCache - insertCoupon(orderFormId: ID, text: String): OrderForm! @withOrderFormId + insertCoupon(orderFormId: ID, text: String): OrderForm! @withOrderFormId @noCache estimateShipping(orderFormId: ID, address: AddressInput): OrderForm! - @withOrderFormId + @withOrderFormId @noCache selectDeliveryOption(orderFormId: ID, deliveryOptionId: String): OrderForm! - @withOrderFormId + @withOrderFormId @noCache selectPickupOption( orderFormId: ID pickupOptionId: String itemId: String - ): OrderForm! @withOrderFormId + ): OrderForm! @withOrderFormId @noCache """ Changes the currently selected address in the shipping data of the OrderForm """ updateSelectedAddress(orderFormId: ID, input: AddressInput!): OrderForm! - @withOrderFormId + @withOrderFormId @noCache savePaymentToken( orderFormId: ID paymentTokens: [PaymentToken] - ): SavePaymentTokenPayload @withOrderFormId + ): SavePaymentTokenPayload @withOrderFormId @noCache updateOrderFormProfile(orderFormId: ID, input: UserProfileInput!): OrderForm! @withOrderFormId - @cacheControl(scope: PRIVATE) + @noCache updateClientPreferencesData( orderFormId: ID input: ClientPreferencesDataInput! - ): OrderForm! @withOrderFormId @cacheControl(scope: PRIVATE) + ): OrderForm! @withOrderFormId @noCache updateOrderFormPayment(orderFormId: ID, input: PaymentDataInput!): OrderForm! @withOrderFormId - @cacheControl(scope: PRIVATE) + @noCache setManualPrice(orderFormId: ID, input: ManualPriceInput!): OrderForm! @withOrderFormId - @cacheControl(scope: PRIVATE) + @noCache updateItemsOrdination( orderFormId: ID ascending: Boolean! criteria: ItemsOrdinationCriteria! - ): OrderForm! @withOrderFormId @cacheControl(scope: PRIVATE) + ): OrderForm! @withOrderFormId @noCache clearOrderFormMessages(orderFormId: ID): OrderForm! @withOrderFormId - @cacheControl(scope: PRIVATE) + @noCache updateOrderFormOpenTextField( orderFormId: ID input: OrderFormOpenTextInput! - ): OrderForm! @withOrderFormId @cacheControl(scope: PRIVATE) + ): OrderForm! @withOrderFormId @noCache updateOrderFormMarketingData(input: MarketingDataInput!): OrderForm! @withOrderFormId - @cacheControl(scope: PRIVATE) + @noCache } diff --git a/manifest.json b/manifest.json index 8583dc09..d010ae76 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "name": "checkout-graphql", "vendor": "vtex", - "version": "0.62.0", + "version": "0.63.0-beta.0", "title": "Checkout GraphQL", "description": "Checkout GraphQL API", "builders": { diff --git a/node/directives/index.ts b/node/directives/index.ts index 1cdb31e6..b345da90 100644 --- a/node/directives/index.ts +++ b/node/directives/index.ts @@ -1,7 +1,9 @@ import { WithSegment } from './withSegment' import { WithOrderFormId } from './withOrderFormId' +import { NoCache } from './noCache' export const schemaDirectives = { withSegment: WithSegment, withOrderFormId: WithOrderFormId, + noCache: NoCache, } diff --git a/node/directives/noCache.ts b/node/directives/noCache.ts new file mode 100644 index 00000000..f9661351 --- /dev/null +++ b/node/directives/noCache.ts @@ -0,0 +1,19 @@ + +import { defaultFieldResolver, GraphQLField } from 'graphql' +import { SchemaDirectiveVisitor } from 'graphql-tools' + +export class NoCache extends SchemaDirectiveVisitor { + public visitFieldDefinition(field: GraphQLField) { + const { resolve = defaultFieldResolver } = field + field.resolve = async (root: any, args: any, ctx: Context, info: any) => { + const { + graphql: { cacheControl } + } = ctx + + cacheControl.noCache = true + cacheControl.noStore = true + + return resolve(root, args, ctx, info) + } + } +} diff --git a/node/resolvers/orderForm.ts b/node/resolvers/orderForm.ts index b02e1140..046dc73e 100644 --- a/node/resolvers/orderForm.ts +++ b/node/resolvers/orderForm.ts @@ -181,13 +181,9 @@ export const queries = { const { clients, vtex, - graphql: { cacheControl }, } = ctx const { orderFormId = vtex.orderFormId, refreshOutdatedData } = args - cacheControl.noCache = true - cacheControl.noStore = true - let { data: newOrderForm, headers } = await clients.checkout.orderFormRaw( orderFormId ?? undefined, refreshOutdatedData ?? undefined diff --git a/node/resolvers/profile.ts b/node/resolvers/profile.ts index 3f660f72..05d2e72a 100644 --- a/node/resolvers/profile.ts +++ b/node/resolvers/profile.ts @@ -6,12 +6,8 @@ export const queries = { ): Promise => { const { clients, - graphql: { cacheControl }, } = ctx - cacheControl.noCache = true - cacheControl.noStore = true - const profile = await clients.checkout.getProfile(email) return profile diff --git a/node/yarn.lock b/node/yarn.lock index cb926a8c..c6dce656 100644 --- a/node/yarn.lock +++ b/node/yarn.lock @@ -5707,7 +5707,7 @@ static-extend@^0.1.1: define-property "^0.2.5" object-copy "^0.1.0" -"stats-lite@github:vtex/node-stats-lite#dist": +stats-lite@vtex/node-stats-lite#dist: version "2.2.0" resolved "https://codeload.github.com/vtex/node-stats-lite/tar.gz/1b0d39cc41ef7aaecfd541191f877887a2044797" dependencies: