-
Notifications
You must be signed in to change notification settings - Fork 14
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 #157 from vtex-apps/fix/add-no-cache
fix: Add no cache directives
- Loading branch information
Showing
8 changed files
with
48 additions
and
33 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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
directive @withSegment on FIELD_DEFINITION | ||
|
||
directive @withOrderFormId on FIELD_DEFINITION | ||
directive @withOrderFormId on FIELD_DEFINITION | ||
|
||
directive @noCache on FIELD_DEFINITION |
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
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, | ||
} |
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,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) | ||
} | ||
} | ||
} |
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