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

Support Object Extensions #5

Closed
zvictor opened this issue Apr 15, 2020 · 3 comments
Closed

Support Object Extensions #5

zvictor opened this issue Apr 15, 2020 · 3 comments

Comments

@zvictor
Copy link
Owner

zvictor commented Apr 15, 2020

Object type extensions are used to represent a type which has been extended from some original type.

from http://spec.graphql.org/draft/#sec-Object-Extensions

It's easy to add additional fields to existing types using the extend keyword. Using extend is particularly useful in avoiding a large list of fields on root Queries and Mutations.

from https://www.apollographql.com/docs/graphql-tools/generate-schema/#extending-types


In our repo we could see it in action in the modularised example. The sayHello resolver is a UDF that belongs to the accounts folder, but we need to define it in the root type Query because right now we can't extend Query anywhere else:

https://github.com/zvictor/faugra/blob/6a6446bce541ae1c41e569984b9ff553bc0410c0/examples/modularized/Query.gql#L5

@lregnier
Copy link

lregnier commented Jun 16, 2020

Hi, @zvictor! If you were able to extend from the root types (Query and Mutation), that should be enough for covering this use case, right? In other words, you're not looking for extending for other user-defined types (e.g. User, etc), at least initially?

The former should be a much more straightforward change to implement within Fauna than the latter.

@zvictor
Copy link
Owner Author

zvictor commented Jun 17, 2020

In short: Yes, extending the root types is enough for now.
That could be processed inside fauna or even by @graphql-toolkit/schema-merging at push-schema.js

Either one converting the extend instruction into the extended object is fine for faugra.


Long answer: I am in favour of modularised development and I believe nested mutations would play a very important role in the faugra context.

If I have a type User in my accounts module and I want to define a changeName mutation for it, it doesn't make sense that I define changeName in a global scope. I would rather define changeName inside User:

type User {
  name
  age
  changeName(name: String!): String! @resolver(name: "changeAccountsUserName") 
}

That being said, nested mutations have known dangerous issues and the community has not come to an agreement on it yet:

So, for now, "object extensions" of the root types would be our workaround for this issue. I don't yet see a strong use case for extending other types, such as user-defined types.

@zvictor
Copy link
Owner Author

zvictor commented Sep 24, 2020

with the migration from @graphql-toolkit to @graphql-tools implemented today, we can now use extend 🎉

@zvictor zvictor closed this as completed Sep 24, 2020
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

2 participants