-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use the isSchema predicate instead of instanceof checks * Create a final `else` case for unexpected results of the _schema variable * Add tests around AS Base constructor to validate previous and new behavior
- Loading branch information
1 parent
73cdf0d
commit f20c5df
Showing
2 changed files
with
55 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
packages/apollo-server-core/src/__tests__/ApolloServerBase.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { ApolloServerBase } from '../ApolloServer'; | ||
import { buildServiceDefinition } from '@apollographql/apollo-tools'; | ||
import gql from 'graphql-tag'; | ||
|
||
const typeDefs = gql` | ||
type Query { | ||
hello: String | ||
} | ||
`; | ||
|
||
const resolvers = { | ||
Query: { | ||
hello() { | ||
return 'world'; | ||
}, | ||
}, | ||
}; | ||
|
||
describe('ApolloServerBase construction', () => { | ||
it('succeeds when a valid configuration options are provided to typeDefs and resolvers', () => { | ||
expect(() => new ApolloServerBase({ typeDefs, resolvers })).not.toThrow(); | ||
}); | ||
|
||
it('succeeds when a valid GraphQLSchema is provided to the schema configuration option', () => { | ||
expect( | ||
() => | ||
new ApolloServerBase({ | ||
schema: buildServiceDefinition([{ typeDefs, resolvers }]).schema, | ||
}), | ||
).not.toThrow(); | ||
}); | ||
|
||
it('throws when a GraphQLSchema is not provided to the schema configuration option', () => { | ||
expect(() => { | ||
new ApolloServerBase({ | ||
schema: {}, | ||
}); | ||
}).toThrowErrorMatchingInlineSnapshot( | ||
`"ApolloServer encountered a programming error. For some reason, we were unable to resolve a valid GraphQLSchema. Please open an issue on the apollo-server repo with a reproduction of this error if possible."`, | ||
); | ||
}); | ||
|
||
it('throws when the no schema configuration option is provided', () => { | ||
expect(() => { | ||
new ApolloServerBase({}); | ||
}).toThrowErrorMatchingInlineSnapshot( | ||
`"Apollo Server requires either an existing schema, modules or typeDefs"`, | ||
); | ||
}); | ||
}); |