Skip to content

Commit

Permalink
fix: Change cache key from typedefs to endpoint
Browse files Browse the repository at this point in the history
Fixes #81
  • Loading branch information
maticzav committed Nov 20, 2018
1 parent d06c79b commit 2c51846
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class Prisma extends Binding {
const token = secret ? sign({}, secret!) : undefined
const link = makePrismaLink({ endpoint: endpoint!, token, debug })

const remoteSchema = getCachedRemoteSchema(typeDefs, sharedLink)
const remoteSchema = getCachedRemoteSchema(endpoint, typeDefs, sharedLink)

const before = () => {
sharedLink.setInnerLink(link)
Expand Down
12 changes: 6 additions & 6 deletions src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { SharedLink } from './SharedLink'
import { makeRemoteExecutableSchema } from 'graphql-tools'

const typeDefsCache: { [schemaPath: string]: string } = {}
const remoteSchemaCache: { [typeDefs: string]: GraphQLSchema } = {}
const remoteSchemaCache: { [endpoint: string]: GraphQLSchema } = {}

export function getCachedTypeDefs(schemaPath: string): string {
if (typeDefsCache[schemaPath]) {
Expand All @@ -18,19 +18,19 @@ export function getCachedTypeDefs(schemaPath: string): string {
}

export function getCachedRemoteSchema(
endpoint: string,
typeDefs: string,
link: SharedLink,
): GraphQLSchema {
if (remoteSchemaCache[typeDefs]) {
return remoteSchemaCache[typeDefs]
if (remoteSchemaCache[endpoint]) {
return remoteSchemaCache[endpoint]
}

const remoteSchema = makeRemoteExecutableSchema({
// TODO fix typings
link: link as any,
link: link,
schema: typeDefs,
})
remoteSchemaCache[typeDefs] = remoteSchema
remoteSchemaCache[endpoint] = remoteSchema

return remoteSchema
}

0 comments on commit 2c51846

Please sign in to comment.