Skip to content

Commit

Permalink
Upgrade to newer apollo-server-types which declares info.cacheControl
Browse files Browse the repository at this point in the history
Also do some other code review feedback.
  • Loading branch information
glasser committed Jul 20, 2021
1 parent ee2ea53 commit 1c968d7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 117 deletions.
2 changes: 1 addition & 1 deletion federation-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"dependencies": {
"apollo-graphql": "^0.9.3",
"apollo-server-types": "^3.0.0",
"apollo-server-types": "^3.0.2",
"lodash.xorby": "^4.7.0"
},
"peerDependencies": {
Expand Down
18 changes: 6 additions & 12 deletions federation-js/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,7 @@ import {
isObjectType,
} from 'graphql';
import { PromiseOrValue } from 'graphql/jsutils/PromiseOrValue';
import { CacheHint, CachePolicy } from 'apollo-server-types';

declare module 'graphql/type/definition' {
interface GraphQLResolveInfo {
cacheControl: {
cacheHint: CachePolicy;
setCacheHint(hint: CacheHint): void;
cacheHintFromType(t: GraphQLCompositeType): CacheHint | undefined;
};
}
}
import { CacheHint } from 'apollo-server-types';

export const EntityType = new GraphQLUnionType({
name: '_Entity',
Expand Down Expand Up @@ -98,11 +88,15 @@ export const entitiesField: GraphQLFieldConfig<any, any> = {
);
}

// Note that while our TypeScript types (as of apollo-server-types@3.0.2)
// tell us that cacheControl and restrict are always defined, we want to
// avoid throwing when used with Apollo Server 2 which doesn't have
// `restrict`, or if the cache control plugin has been disabled.
if (info.cacheControl?.cacheHint?.restrict) {
const cacheHint: CacheHint | undefined =
info.cacheControl.cacheHintFromType(type);

if (cacheHint?.maxAge || cacheHint?.scope) {
if (cacheHint) {
info.cacheControl.cacheHint.restrict(cacheHint);
}
}
Expand Down
106 changes: 2 additions & 104 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1c968d7

Please sign in to comment.