can reproduce getIntrospectionQuery error with minimal schema

This commit is contained in:
eric-burel 2019-01-23 19:51:30 +01:00
parent 9d27f386c9
commit c7aeaea949
2 changed files with 101 additions and 2 deletions

View file

@ -2,12 +2,17 @@ import {
createApolloServer,
setupWebApp,
defaultConfig,
initGraphQL
initGraphQL,
initContext,
computeContextFromReq
} from '../../lib/server/apollo-server';
import {GraphQLSchema} from '../../lib/modules/graphql';
import expect from 'expect';
import { executableSchema } from './fixtures/minimalSchema';
const test = it; // TODO: just before we switch to jest
// @see https://www.apollographql.com/docs/apollo-server/features/testing.html
describe('apollo-server', function() {
let options;
before(function () {
@ -17,7 +22,11 @@ describe('apollo-server', function() {
config: defaultConfig,
// Apollo options
apolloServerOptions: {
schema: GraphQLSchema.getExecutableSchema(),
// TODO: check why this fails. One of the schema defined
// in one of the test file (when running createCollection in a test)
// is not working as expected
//schema: GraphQLSchema.getExecutableSchema(),
schema: executableSchema,
//formatError,
//tracing: getSetting('apolloTracing', Meteor.isDevelopment),
cacheControl: true,
@ -34,4 +43,16 @@ describe('apollo-server', function() {
});
});
describe('setupWebApp', function () { });
describe('compute context', function(){
test.skip('inital context contains data loaders', function(){
// TODO
});
test.skip('initial context contains graphQLSchema context', function(){
// TODO
});
test.skip('initial context is merged with provided context', function(){
// TODO
});
});
});

View file

@ -0,0 +1,78 @@
// blatantly stolen from https://www.apollographql.com/docs/graphql-tools/generate-schema.html
import find from 'lodash/find';
import filter from 'lodash/filter';
import { makeExecutableSchema } from 'graphql-tools';
const typeDefs = `
type Author {
id: Int!
firstName: String
lastName: String
posts: [Post]
}
type Post {
id: Int!
title: String
author: Author
votes: Int
}
# the schema allows the following query:
type Query {
posts: [Post]
author(id: Int!): Author
}
# this schema allows the following mutation:
type Mutation {
upvotePost (
postId: Int!
): Post
}
`;
// example data
const authors = [
{ id: 1, firstName: 'Tom', lastName: 'Coleman' },
{ id: 2, firstName: 'Sashko', lastName: 'Stubailo' },
{ id: 3, firstName: 'Mikhail', lastName: 'Novikov' },
];
const posts = [
{ id: 1, authorId: 1, title: 'Introduction to GraphQL', votes: 2 },
{ id: 2, authorId: 2, title: 'Welcome to Meteor', votes: 3 },
{ id: 3, authorId: 2, title: 'Advanced GraphQL', votes: 1 },
{ id: 4, authorId: 3, title: 'Launchpad is Cool', votes: 7 },
];
const resolvers = {
Query: {
posts: () => posts,
author: (_, { id }) => find(authors, { id }),
},
Mutation: {
upvotePost: (_, { postId }) => {
const post = find(posts, { id: postId });
if (!post) {
throw new Error(`Couldn't find post with id ${postId}`);
}
post.votes += 1;
return post;
},
},
Author: {
posts: author => filter(posts, { authorId: author.id }),
},
Post: {
author: post => find(authors, { id: post.authorId }),
},
};
export const executableSchema = makeExecutableSchema({
typeDefs,
resolvers
});