Skip to content

Commit

Permalink
[response-cache] support @CacheControl(scope: CacheControlScope)
Browse files Browse the repository at this point in the history
chore(dependencies): updated changesets for modified dependencies

use metadata helper

chore(dependencies): updated changesets for modified dependencies

add tests for stream and defer directives

changeset

update envelop plugin to stable release

chore(dependencies): updated changesets for modified dependencies

add documentation

fix response cache usage with subscriptions

chore(dependencies): updated changesets for modified dependencies
  • Loading branch information
EmrysMyrddin authored and ardatan committed Sep 27, 2023
1 parent 725deb0 commit 562a250
Show file tree
Hide file tree
Showing 5 changed files with 1,203 additions and 966 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@graphql-yoga/plugin-response-cache': patch
---
dependencies updates:
- Updated dependency [`@envelop/response-cache@5.3.1-alpha-20230920124022-44708a76`
↗︎](https://www.npmjs.com/package/@envelop/response-cache/v/5.3.1) (from `^5.1.0`, in
`dependencies`)
83 changes: 40 additions & 43 deletions packages/plugins/response-cache/__tests__/response-cache.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createSchema, createYoga } from 'graphql-yoga';
import { createSchema, createYoga, Repeater } from 'graphql-yoga';
import { cacheControlDirective } from '@envelop/response-cache';
import { useDeferStream } from '@graphql-yoga/plugin-defer-stream';
import { createInMemoryCache, useResponseCache } from '@graphql-yoga/plugin-response-cache';
Expand Down Expand Up @@ -782,60 +782,57 @@ describe('should support async results', () => {
});
});

it('should allow to create the cache outside of the plugin', async () => {
const onEnveloped = jest.fn();
it('should allow subscriptions and ignore it', async () => {
const source = (async function* foo() {
yield { hi: 'hi' };
yield { hi: 'hello' };
yield { hi: 'bonjour' };
})();

const schema = createSchema({
typeDefs: /* GraphQL */ `
type Subscription {
hi: String!
}
type Query {
hi: String!
}
`,
resolvers: {
Subscription: {
hi: {
subscribe: () => source,
},
},
},
});

const yoga = createYoga({
schema,
plugins: [
useResponseCache({
session: () => null,
includeExtensionMetadata: true,
cache: createInMemoryCache(),
}),
{
onEnveloped,
},
],
});
const response = await yoga.fetch('http://localhost:3000/graphql', {
method: 'POST',
headers: {
'content-type': 'application/json',
},
body: JSON.stringify({ query: '{ _ }' }),
});

expect(response.status).toEqual(200);
const body = await response.json();
expect(body).toEqual({
data: {
_: 'DUMMY',
},
extensions: {
responseCache: {
didCache: true,
hit: false,
ttl: null,
},
},
});
const response2 = await yoga.fetch('http://localhost:3000/graphql', {
const response = await yoga.fetch('http://yoga/graphql', {
method: 'POST',
headers: {
'content-type': 'application/json',
accept: 'text/event-stream',
},
body: JSON.stringify({ query: '{ _ }' }),
});
const body2 = await response2.json();
expect(body2).toMatchObject({
data: {
_: 'DUMMY',
},
extensions: {
responseCache: {
hit: true,
},
},
body: JSON.stringify({
query: /* GraphQL */ `
subscription {
hi
}
`,
}),
});
expect(onEnveloped).toHaveBeenCalledTimes(1);

const result = await response.text();
expect(result).toContain(JSON.stringify({ data: { hi: 'hi' } }));
expect(result).toContain(JSON.stringify({ data: { hi: 'hello' } }));
expect(result).toContain(JSON.stringify({ data: { hi: 'bonjour' } }));
});
1 change: 1 addition & 0 deletions packages/plugins/response-cache/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ExecutionResult } from 'graphql';
import { Maybe, Plugin, PromiseOrValue, YogaInitialContext, YogaLogger } from 'graphql-yoga';
import {
createInMemoryCache,

Check failure on line 4 in packages/plugins/response-cache/src/index.ts

View workflow job for this annotation

GitHub Actions / website-check

Individual declarations in merged declaration 'createInMemoryCache' must be all exported or all local.

Check failure on line 4 in packages/plugins/response-cache/src/index.ts

View workflow job for this annotation

GitHub Actions / website-check

Import declaration conflicts with local declaration of 'createInMemoryCache'.

Check failure on line 4 in packages/plugins/response-cache/src/index.ts

View workflow job for this annotation

GitHub Actions / integration / nodejs v16 / graphql v16.6.0

Individual declarations in merged declaration 'createInMemoryCache' must be all exported or all local.

Check failure on line 4 in packages/plugins/response-cache/src/index.ts

View workflow job for this annotation

GitHub Actions / integration / nodejs v16 / graphql v16.6.0

Import declaration conflicts with local declaration of 'createInMemoryCache'.

Check failure on line 4 in packages/plugins/response-cache/src/index.ts

View workflow job for this annotation

GitHub Actions / benchmarks

Individual declarations in merged declaration 'createInMemoryCache' must be all exported or all local.

Check failure on line 4 in packages/plugins/response-cache/src/index.ts

View workflow job for this annotation

GitHub Actions / benchmarks

Import declaration conflicts with local declaration of 'createInMemoryCache'.

Check failure on line 4 in packages/plugins/response-cache/src/index.ts

View workflow job for this annotation

GitHub Actions / deployment

Individual declarations in merged declaration 'createInMemoryCache' must be all exported or all local.

Check failure on line 4 in packages/plugins/response-cache/src/index.ts

View workflow job for this annotation

GitHub Actions / deployment

Import declaration conflicts with local declaration of 'createInMemoryCache'.

Check failure on line 4 in packages/plugins/response-cache/src/index.ts

View workflow job for this annotation

GitHub Actions / apollo-federation-compatibility

Individual declarations in merged declaration 'createInMemoryCache' must be all exported or all local.

Check failure on line 4 in packages/plugins/response-cache/src/index.ts

View workflow job for this annotation

GitHub Actions / apollo-federation-compatibility

Import declaration conflicts with local declaration of 'createInMemoryCache'.

Check failure on line 4 in packages/plugins/response-cache/src/index.ts

View workflow job for this annotation

GitHub Actions / integration / nodejs v18 / graphql v16.6.0

Individual declarations in merged declaration 'createInMemoryCache' must be all exported or all local.

Check failure on line 4 in packages/plugins/response-cache/src/index.ts

View workflow job for this annotation

GitHub Actions / integration / nodejs v18 / graphql v16.6.0

Import declaration conflicts with local declaration of 'createInMemoryCache'.

Check failure on line 4 in packages/plugins/response-cache/src/index.ts

View workflow job for this annotation

GitHub Actions / integration / nodejs v18 / graphql v15.8.0

Individual declarations in merged declaration 'createInMemoryCache' must be all exported or all local.

Check failure on line 4 in packages/plugins/response-cache/src/index.ts

View workflow job for this annotation

GitHub Actions / integration / nodejs v18 / graphql v15.8.0

Import declaration conflicts with local declaration of 'createInMemoryCache'.

Check failure on line 4 in packages/plugins/response-cache/src/index.ts

View workflow job for this annotation

GitHub Actions / integration / nodejs v16 / graphql v15.8.0

Individual declarations in merged declaration 'createInMemoryCache' must be all exported or all local.

Check failure on line 4 in packages/plugins/response-cache/src/index.ts

View workflow job for this annotation

GitHub Actions / integration / nodejs v16 / graphql v15.8.0

Import declaration conflicts with local declaration of 'createInMemoryCache'.

Check failure on line 4 in packages/plugins/response-cache/src/index.ts

View workflow job for this annotation

GitHub Actions / esm

Individual declarations in merged declaration 'createInMemoryCache' must be all exported or all local.

Check failure on line 4 in packages/plugins/response-cache/src/index.ts

View workflow job for this annotation

GitHub Actions / esm

Import declaration conflicts with local declaration of 'createInMemoryCache'.

Check failure on line 4 in packages/plugins/response-cache/src/index.ts

View workflow job for this annotation

GitHub Actions / leaks / nodejs v16 / graphql v15.8.0

Individual declarations in merged declaration 'createInMemoryCache' must be all exported or all local.

Check failure on line 4 in packages/plugins/response-cache/src/index.ts

View workflow job for this annotation

GitHub Actions / leaks / nodejs v16 / graphql v15.8.0

Import declaration conflicts with local declaration of 'createInMemoryCache'.

Check failure on line 4 in packages/plugins/response-cache/src/index.ts

View workflow job for this annotation

GitHub Actions / typecheck

Individual declarations in merged declaration 'createInMemoryCache' must be all exported or all local.

Check failure on line 4 in packages/plugins/response-cache/src/index.ts

View workflow job for this annotation

GitHub Actions / typecheck

Import declaration conflicts with local declaration of 'createInMemoryCache'.

Check failure on line 4 in packages/plugins/response-cache/src/index.ts

View workflow job for this annotation

GitHub Actions / leaks / nodejs v18 / graphql v15.8.0

Individual declarations in merged declaration 'createInMemoryCache' must be all exported or all local.

Check failure on line 4 in packages/plugins/response-cache/src/index.ts

View workflow job for this annotation

GitHub Actions / leaks / nodejs v18 / graphql v15.8.0

Import declaration conflicts with local declaration of 'createInMemoryCache'.

Check failure on line 4 in packages/plugins/response-cache/src/index.ts

View workflow job for this annotation

GitHub Actions / unit / nodejs v16 / graphql v15.8.0

Individual declarations in merged declaration 'createInMemoryCache' must be all exported or all local.

Check failure on line 4 in packages/plugins/response-cache/src/index.ts

View workflow job for this annotation

GitHub Actions / unit / nodejs v16 / graphql v15.8.0

Import declaration conflicts with local declaration of 'createInMemoryCache'.

Check failure on line 4 in packages/plugins/response-cache/src/index.ts

View workflow job for this annotation

GitHub Actions / unit / nodejs v18 / graphql v16.6.0

Individual declarations in merged declaration 'createInMemoryCache' must be all exported or all local.

Check failure on line 4 in packages/plugins/response-cache/src/index.ts

View workflow job for this annotation

GitHub Actions / unit / nodejs v18 / graphql v16.6.0

Import declaration conflicts with local declaration of 'createInMemoryCache'.

Check failure on line 4 in packages/plugins/response-cache/src/index.ts

View workflow job for this annotation

GitHub Actions / leaks / nodejs v16 / graphql v16.6.0

Individual declarations in merged declaration 'createInMemoryCache' must be all exported or all local.

Check failure on line 4 in packages/plugins/response-cache/src/index.ts

View workflow job for this annotation

GitHub Actions / leaks / nodejs v16 / graphql v16.6.0

Import declaration conflicts with local declaration of 'createInMemoryCache'.

Check failure on line 4 in packages/plugins/response-cache/src/index.ts

View workflow job for this annotation

GitHub Actions / leaks / nodejs v18 / graphql v16.6.0

Individual declarations in merged declaration 'createInMemoryCache' must be all exported or all local.

Check failure on line 4 in packages/plugins/response-cache/src/index.ts

View workflow job for this annotation

GitHub Actions / leaks / nodejs v18 / graphql v16.6.0

Import declaration conflicts with local declaration of 'createInMemoryCache'.

Check failure on line 4 in packages/plugins/response-cache/src/index.ts

View workflow job for this annotation

GitHub Actions / unit / nodejs v16 / graphql v16.6.0

Individual declarations in merged declaration 'createInMemoryCache' must be all exported or all local.

Check failure on line 4 in packages/plugins/response-cache/src/index.ts

View workflow job for this annotation

GitHub Actions / unit / nodejs v16 / graphql v16.6.0

Import declaration conflicts with local declaration of 'createInMemoryCache'.

Check failure on line 4 in packages/plugins/response-cache/src/index.ts

View workflow job for this annotation

GitHub Actions / unit / nodejs v18 / graphql v15.8.0

Individual declarations in merged declaration 'createInMemoryCache' must be all exported or all local.

Check failure on line 4 in packages/plugins/response-cache/src/index.ts

View workflow job for this annotation

GitHub Actions / unit / nodejs v18 / graphql v15.8.0

Import declaration conflicts with local declaration of 'createInMemoryCache'.

Check failure on line 4 in packages/plugins/response-cache/src/index.ts

View workflow job for this annotation

GitHub Actions / alpha / snapshot

Individual declarations in merged declaration 'createInMemoryCache' must be all exported or all local.

Check failure on line 4 in packages/plugins/response-cache/src/index.ts

View workflow job for this annotation

GitHub Actions / alpha / snapshot

Import declaration conflicts with local declaration of 'createInMemoryCache'.

Check failure on line 4 in packages/plugins/response-cache/src/index.ts

View workflow job for this annotation

GitHub Actions / unit / nodejs v20 / graphql v15.8.0

Individual declarations in merged declaration 'createInMemoryCache' must be all exported or all local.

Check failure on line 4 in packages/plugins/response-cache/src/index.ts

View workflow job for this annotation

GitHub Actions / unit / nodejs v20 / graphql v15.8.0

Import declaration conflicts with local declaration of 'createInMemoryCache'.
defaultBuildResponseCacheKey,
BuildResponseCacheKeyFunction as EnvelopBuildResponseCacheKeyFunction,
Cache as EnvelopCache,
Expand Down
Loading

0 comments on commit 562a250

Please sign in to comment.