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 converting graphene types to graphql-core types for better interop #1238

Open
berekuk opened this issue Jul 27, 2020 · 1 comment
Open

Comments

@berekuk
Copy link

berekuk commented Jul 27, 2020

Is your feature request related to a problem? Please describe.
I don't want to buy-in into Graphene as framework, and I might like to convert some parts of my GraphQL server to Graphene without converting ALL of my graphql-related code to Graphene.

Describe the solution you'd like
I'd like Graphene to support something like graphene_object_type.as_graphql_core_type().

@jkimbo says that it's not currently possible because "type generation code in graphene is stateful", but that it might be possible in the future.

Describe alternatives you've considered
I don't see any other pathways to the interop between different graphql libraries.

Additional context
Here's a question I asked on graphene slack:

Hi everyone, I have a general question about python graphql libraries, hope this is the right channel to ask.In the last few months I tried Graphene first, then refactored everything to Ariadne and then recently refactored everything again to the raw graphql-core APIs because I wasn't happy with SDL-first approach.Right now I enjoy my lightweight graphql-core wrappers more than Graphene, Ariadne or Strawberry, so I thought that maybe I should upload them on PyPI. (I probably won't be able to maintain them well enough, but still. Maybe I will, it's worth a try.)But before I do that, I realized that I have a question that I don't fully understand: why do all three well-known python graphql libraries behave like frameworks? In a sense that they reinvent graphql-core objects hierarchy and replace them with their own wrappers which don't play well with others. I feel like this is sub-optimal, because it requires me to do the complete refactoring of my code if I want to adopt any of those, when I could just gradually replace parts of my code with Strawberry's dataclasses or Graphene's Django helpers, if those were presented as graphql-core compatible objects.I think I know two parts of the answer to my question:

  1. Circular imports are tricky (but this can be solved with graphql-core's lambda feature, fields=build_fields and deferred imports in build_fields() body).
  2. Ariadne (and probably others? my memory of Graphene and Strawberry's APIs is a bit lazy) provides a nice way to "register" your types and queries so that you don't have to stitch your final schema by hand with tons of imports and can reference other parts of your graph by names and not by type objects. In other words, they provide dependency injections.

But so far, at least in my experience, both of these reasons turned out to be quite minor and fixable.So, what do you think? Does Python world need a "graphql library" as an alternative to "graphql frameworks"? Why or why not?

(@jkimbo asked me to create a feature request for this in the following discussion)

@fiLLLip
Copy link

fiLLLip commented Oct 1, 2020

If I understand this correctly, I second this. I am using graphql-core, but want to use some of the types, like JSON and DateTime without having to import the entire framework. I think I would take this a step further and create a separate "graphql-core-scalars" repo that can be imported by graphene. Then those who want to use the scalars with graphql-core could import them as well without the extra overhead.

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

No branches or pull requests

2 participants