Skip to content

Commit

Permalink
Merge pull request #157 from vtex-apps/fix/add-no-cache
Browse files Browse the repository at this point in the history
fix: Add no cache directives
  • Loading branch information
tlgimenes authored Oct 7, 2021
2 parents 5901b11 + 8647a90 commit ef637ea
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 33 deletions.
4 changes: 3 additions & 1 deletion graphql/directives.graphql
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
directive @withSegment on FIELD_DEFINITION

directive @withOrderFormId on FIELD_DEFINITION
directive @withOrderFormId on FIELD_DEFINITION

directive @noCache on FIELD_DEFINITION
44 changes: 22 additions & 22 deletions graphql/schema.graphql
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
}
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
2 changes: 2 additions & 0 deletions node/directives/index.ts
Original file line number Diff line number Diff line change
@@ -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,
}
19 changes: 19 additions & 0 deletions node/directives/noCache.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

import { defaultFieldResolver, GraphQLField } from 'graphql'
import { SchemaDirectiveVisitor } from 'graphql-tools'

export class NoCache extends SchemaDirectiveVisitor {
public visitFieldDefinition(field: GraphQLField<any, any>) {
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)
}
}
}
4 changes: 0 additions & 4 deletions node/resolvers/orderForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions node/resolvers/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@ export const queries = {
): Promise<CheckoutProfile> => {
const {
clients,
graphql: { cacheControl },
} = ctx

cacheControl.noCache = true
cacheControl.noStore = true

const profile = await clients.checkout.getProfile(email)

return profile
Expand Down
2 changes: 1 addition & 1 deletion node/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit ef637ea

Please sign in to comment.