Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Either "schema" OR "typeDefs + resolvers" are required. #4684

Closed
JoseJuan81 opened this issue Oct 27, 2020 · 11 comments
Closed

docs: Either "schema" OR "typeDefs + resolvers" are required. #4684

JoseJuan81 opened this issue Oct 27, 2020 · 11 comments
Labels
📝 documentation Focuses on changes to the documentation (docs)

Comments

@JoseJuan81
Copy link

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,
  ...
})
@wmertens
Copy link
Contributor

This is exactly what I do, and it just works. What is the error?

@JoseJuan81
Copy link
Author

@wmertens can you tell me how do you do?

@wmertens
Copy link
Contributor

@JoseJuan81 I do what you write, I pass a GraphQLSchema instance to ApolloServer.

What is the error you're getting

@JoseJuan81
Copy link
Author

JoseJuan81 commented Dec 22, 2020

@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.

@wmertens
Copy link
Contributor

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...

@JoseJuan81
Copy link
Author

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:
Captura de Pantalla 2020-12-22 a la(s) 12 02 30 p  m
Those properties are required and that is confusing.

In the code typeDefs is not required:
Captura de Pantalla 2020-12-22 a la(s) 12 13 51 p  m

The ApolloServer needs one of them.

@abernix abernix added the 📝 documentation Focuses on changes to the documentation (docs) label Dec 31, 2020
@abernix
Copy link
Member

abernix commented Dec 31, 2020

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!)

@abernix abernix changed the title Pass GrapQLSchema Object to ApolloServer docs: Either "schema" OR "typeDefs + resolvers" are required. Dec 31, 2020
@abernix
Copy link
Member

abernix commented Dec 31, 2020

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.

@abernix
Copy link
Member

abernix commented Dec 31, 2020

See also: #4386

@JoseJuan81
Copy link
Author

JoseJuan81 commented Jan 5, 2021

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.

@glasser
Copy link
Member

glasser commented Oct 21, 2022

The docs are pretty clear about this now, I hope.

@glasser glasser closed this as completed Oct 21, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
📝 documentation Focuses on changes to the documentation (docs)
Projects
None yet
Development

No branches or pull requests

4 participants