Hi, apollo team
The apollo-server only accepts SDL syntax when is created (typeDefs and resolvers):
const typeDefs = gql`
type Query {
hello: string
}`
const resolvers = {
Query: {
hello: () => 'Hello world'
}
new ApolloServer({
typeDefs,
resolvers,
...
})
I wish can pass GraphQLSchema object syntax directly into ApolloServer instance.
I like this syntax over SDL but Apollo doesn't support it.
const queryType = new GraphQLObjectType({
name: 'Query',
fields: {
hello: {
name: 'helloField',
type: GraphQLString,
resolve: () => 'Hola mundo',
},
},
});
const _schema = new GraphQLSchema({
query: queryType,
});
new ApolloServer({
schema: _schema,
...
})
This is exactly what I do, and it just works. What is the error?
@wmertens can you tell me how do you do?
@JoseJuan81 I do what you write, I pass a GraphQLSchema instance to ApolloServer.
What is the error you're getting
@wmertens Hi,
I have no errors in my project about this because I'm working with SDL syntax, I just want to pass a GraphQLSchema syntax.
I read in the docs that the typeDefs and resolvers are required: https://www.apollographql.com/docs/apollo-server/api/apollo-server/ so, do I have to pass typeDefs, resolvers and schema props to the ApolloServer?
Maybe the error is in the docs because there is no indication neither example about GraphQLSchema syntax implementations.
So when you try to use your example, you don't get an error, but it also doesn't work? Because my code is pretty much like your example and it just works...
Ok, @wmertens you're right, I just made a small test in development mode and works...
I guess It was a misunderstood, but I recommend to update the apollo docs:

Those properties are required and that is confusing.
In the code typeDefs is not required:

The ApolloServer needs one of them.
It is true that (typeDefs AND resolvers) OR (schema) should be passed. In fact, in federation (when using buildFederatedSchema), it isn't uncommon to use schema: buildFederatedSchema([{ typeDefs, resolvers }]), rather than using typeDefs or resolvers at all!
Generally speaking, PRs are welcome!
cc @StephenBarlow for suggestions on how we might render this effectively (or if we should merely use our words to do so!)
And as the code above points out, there's a third option of using (the incredibly undocumented, I think?) modules approach in lieu of either of them.
I must say, my project now use GraphQLSchema over than SDL and that was somethig that I wanted, so thank you @wmertens and @abernix .
I think you could add more examples in the tutorial about how to use apollo with GraphQLObjects and for Client side It would be nice to include some Vue (with vuex) tutorial.
Regards.