Skip to content

Commit

Permalink
run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick.rehn committed Jun 6, 2024
1 parent bf60ced commit 45271af
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 48 deletions.
8 changes: 6 additions & 2 deletions packages/plugins/response-cache/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export type UseResponseCacheParameter<PluginContext extends Record<string, any>
* List of SchemaCoordinates in format {ObjectType}.{FieldName} which are ignored during scan for entities.
* Defaults to `[]`
*/
ignoreIdFieldsBySchemaCoordinate?: Array<string>
ignoreIdFieldsBySchemaCoordinate?: Array<string>;
/**
* Whether the mutation execution result should be used for invalidating resources.
* Defaults to `true`
Expand Down Expand Up @@ -367,7 +367,11 @@ export function useResponseCache<PluginContext extends Record<string, any> = {}>
const resultTypeNames = unwrapTypenames(fieldConfig.type);
typePerSchemaCoordinateMap.set(schemaCoordinates, resultTypeNames);

if (idFields.includes(fieldName) && !idFieldByTypeName.has(typeName) && !ignoreIdFieldsBySchemaCoordinate?.includes(schemaCoordinates)) {
if (
idFields.includes(fieldName) &&
!idFieldByTypeName.has(typeName) &&
!ignoreIdFieldsBySchemaCoordinate?.includes(schemaCoordinates)
) {
idFieldByTypeName.set(typeName, fieldName);
}

Expand Down
94 changes: 48 additions & 46 deletions packages/plugins/response-cache/test/response-cache.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4035,39 +4035,40 @@ it('calls enabled fn after context building', async () => {
it('id field in body is returned as is and not overwritten', async () => {
expect.assertions(1);
const queryResult = {
'id': "idString", 'header': {'id': {'fieldA': 'Tick', 'fieldB': 'Trick', 'fieldC': 'Track'}, 'someField': 'someData'}
}
id: 'idString',
header: { id: { fieldA: 'Tick', fieldB: 'Trick', fieldC: 'Track' }, someField: 'someData' },
};
const schema = makeExecutableSchema({
typeDefs: /* GraphQL */ `
type Query {
subgraphObject: SubgraphObject
},
}
type SubgraphObject {
id: String,
header: Header,
},
id: String
header: Header
}
type Header {
id: IdObject,
id: IdObject
someField: String
},
}
type IdObject {
fieldA: String,
fieldB: String,
fieldC: String,
fieldA: String
fieldB: String
fieldC: String
}
`,
resolvers: { Query: { subgraphObject: () => queryResult } },
});
const testkit = createTestkit(
[
useEngine({ ...GraphQLJS, execute: normalizedExecutor, subscribe: normalizedExecutor }),
useResponseCache({
session: () => null,
ttl:0,
ignoreIdFieldsBySchemaCoordinate:['Header.id']
}),
],
schema,
[
useEngine({ ...GraphQLJS, execute: normalizedExecutor, subscribe: normalizedExecutor }),
useResponseCache({
session: () => null,
ttl: 0,
ignoreIdFieldsBySchemaCoordinate: ['Header.id'],
}),
],
schema,
);

const document = /* GraphQL */ `
Expand Down Expand Up @@ -4098,42 +4099,44 @@ it('id field in body is returned as is and not overwritten', async () => {
it('id field in body overwritten and request fails', async () => {
expect.assertions(1);
const queryResult = {
'id': "idString", 'header': {'id': {'fieldA': 'Tick', 'fieldB': 'Trick', 'fieldC': 'Track'}, 'someField': 'someData'}
}
id: 'idString',
header: { id: { fieldA: 'Tick', fieldB: 'Trick', fieldC: 'Track' }, someField: 'someData' },
};
const schema = makeExecutableSchema({
typeDefs: /* GraphQL */ `
type Query {
subgraphObject: SubgraphObject
},
}
type SubgraphObject {
id: String,
header: Header!,
},
id: String
header: Header!
}
type Header {
id: IdObject!,
id: IdObject!
someField: String
},
}
type IdObject {
fieldA: String!,
fieldB: String!,
fieldC: String!,
fieldA: String!
fieldB: String!
fieldC: String!
}
`,
resolvers: { Query: { subgraphObject: () => queryResult } },
});
const testkit = createTestkit(
[
useEngine({ ...GraphQLJS, execute: normalizedExecutor, subscribe: normalizedExecutor }),
useResponseCache({
enabled(context: any): boolean {
return true;
}, session(context: any): string | undefined | null {
return "sessionString";
},
ttl:0
}),
],
schema,
[
useEngine({ ...GraphQLJS, execute: normalizedExecutor, subscribe: normalizedExecutor }),
useResponseCache({
enabled(context: any): boolean {
return true;
},
session(context: any): string | undefined | null {
return 'sessionString';
},
ttl: 0,
}),
],
schema,
);

const document = /* GraphQL */ `
Expand All @@ -4152,6 +4155,5 @@ it('id field in body overwritten and request fails', async () => {
}
`;

await expect( testkit.execute(document)).rejects.toThrow(TypeError);

});
await expect(testkit.execute(document)).rejects.toThrow(TypeError);
});

0 comments on commit 45271af

Please sign in to comment.