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

[feature] Merge query #3

Open
ilan-schemoul opened this issue Mar 22, 2017 · 9 comments
Open

[feature] Merge query #3

ilan-schemoul opened this issue Mar 22, 2017 · 9 comments

Comments

@ilan-schemoul
Copy link

Hello,
You allows to split schemas/resolvers in different files however we cannot define more than one Query otherwise the error Error: Must provide only one query type in schema is thrown. See apollographql/apollo-server#43 to find solutions to merge queries into a single one.

@ilan-schemoul ilan-schemoul changed the title [feature] [feature] Merge query Mar 22, 2017
@ilan-schemoul
Copy link
Author

Anyway we can create a function to merge our schemas/resolvers then use this package to merge merged schemas with the one of meteor-apollo-accounts but as you created a seperate package to merge schemas/resolvers then I suppose you'd prefer fulfil entirely its function and maybe become the solution de facto for apollographql/apollo-server#43 ?

@nicolaslopezj
Copy link
Owner

I'm sorry, I can't understand what you want to achieve. Can you show me an example?

@ilan-schemoul
Copy link
Author

If I load two schemas :

loadSchema({ typeDefsOne, resolvers });
loadSchema({ typeDefsTwo, resolvers });

typeDefsOne :

  type Query {
    drugs(name: String, category_id: String): [Drug]
  }

typeDefsTwo :

  type Query {
    users(id: Int): [User]
}

So if I load these both schemas and then this error is thrown type Query there is Error: Must provide only one query type in schemawhen ImakeExecutableSchema`. I'd like this package to merge my type Query into one so I don't have to define all my queries in one file.

@nicolaslopezj
Copy link
Owner

Are you using const schema = makeExecutableSchema(getSchema()) to get the merged schema?

@ilan-schemoul
Copy link
Author

As this package doesn't merge queries if I load two separate type Query then the error Must provide only one query type in schema is thrown when I do makeExecutableSchema(getSchema())
To prevent this error to be thrown I've defined all my type Query in one single seperated file.
I'd like to be able to put a query in each file I've have. So the fix would be your package to merge all queries in one. I.E type Query { x } type Query { y } would be with your package type Query { x + y }.

@nicolaslopezj
Copy link
Owner

Maybe you're using this wrong, because that's exactly what this package does

@ilan-schemoul
Copy link
Author

I wish it was the case but if I have multiple type Query what's inside these type Query are unfortunately not merged.

@micchickenburger
Copy link

Hey @nicolaslopezj, @NitroBAY is correct. If you have typeDefs with duplicate types, you'll encounter an error. For instance, Error: Type "Mutation" was defined more than once. This is a problem because at times Query and Mutation definitions need to merge.

As an example, your apollo-accounts package adds a Mutation typedef during initAccounts:

type LoginMethodResponse {
  # Id of the user logged in user
  id: String!
  # Token of the connection
  token: String!
  # Expiration date for the token
  tokenExpires: Float!
  # The logged in user
  user: User
}

input CreateUserProfileInput {
  name: String
}

type SuccessResponse {
  # True if it succeeded
  success: Boolean
}

input HashedPassword {
  # The hashed password
  digest: String!
  # Algorithm used to hash the password
  algorithm: String!
}

type Mutation {
  # Log the user in with a password.
  loginWithPassword (username: String, email: String, password: HashedPassword, plainPassword: String): LoginMethodResponse

  # Create a new user.
  createUser (username: String, email: String, password: HashedPassword, plainPassword: String, profile: CreateUserProfileInput): LoginMethodResponse

  # Change the current user\'s password. Must be logged in.
  changePassword (oldPassword: HashedPassword!, newPassword: HashedPassword!): SuccessResponse

  # Request a forgot password email.
  forgotPassword (email: String!): SuccessResponse

  # Reset the password for a user using a token received in email. Logs the user in afterwards.
  resetPassword (newPassword: HashedPassword!, token: String!): LoginMethodResponse

  # Log the user out.
  logout (token: String!): SuccessResponse

  # Marks the user\'s email address as verified. Logs the user in afterwards.
  verifyEmail (token: String!): LoginMethodResponse

  # Send an email with a link the user can use verify their email address.
  resendVerificationEmail (email: String): SuccessResponse
}

This prevents applications from having their own Mutations.

@ikatun
Copy link

ikatun commented Feb 6, 2018

@NitroBAY You can use this library for stitching the schema that way.
https://github.com/okgrow/merge-graphql-schemas

You can also define type Query { ...something... } and then keep using extend type Query{...}.
Same thing for Mutation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants