graphql-python / graphql-python/graphene

Support converting graphene types to graphql-core types for better interop

Open
#1,238 1 comment 0 reactions 0 assignees View on GitHub
✨ enhancement
Dominant language
Python
Stars
8.2k
Forks
818
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.