$ npm install --save graphql-memo
import memo from 'graphql-memo';
const { cache } = memo({ store: new Map() });
const Query = new GraphQLObjectType({
name: 'Query',
fields: () => ({
hello: {
type: GraphQLString,
args: {
name: { type: GraphQLString, defaultValue: 'world' },
},
- resolve: async (root, { name }, context, info) => {
- return Promise.resolve(name);
- },
+ resolve: cache(async (root, { name }, context, info) => {
+ return Promise.resolve(name);
+ }),
},
}),
});
๐