trialspark / graphene-stubs Goto Github PK
View Code? Open in Web Editor NEWStubs and a plugin for Graphene
License: MIT License
Stubs and a plugin for Graphene
License: MIT License
Graphene gets mad if you put any attributes on an ObjectType
besides Argument
s, Field
s, resolver methods, and class Meta
(and maybe some more stuff I don't know about).
Since defining another type of attribute on an ObjectType
throws a runtime error, it would be useful if it threw one at compile time as well.
Mypy has refactored strict_optional_set
(https://github.com/python/mypy/blob/v0.950/mypy/state.py) and this import is breaking the loading of graphene_plugin.
setup.cfg:206: error: Error importing plugin "graphene_plugin": cannot import name 'strict_optional_set' from 'mypy.state' (.../lib/python3.9/site-packages/mypy/state.cpython-39-darwin.so) [misc]```
Hi,
I was messing around with the master branch and noticed the following:
import graphene
class TestQuery(graphene.ObjectType):
field = graphene.Field(String)
@staticmethod
def resolve_field(_: None, __: graphene.ResolveInfo) -> Optional[str]:
return 'hi'
This however returns the following error:
main:9: error: No field with name "field" defined
When changing the graphene.Field
to from graphene import Field
and then just use Field
it works fine.
Here's a test case (that currently fails) so you can reproduce it in pytest:
[case test_field_resolve_with_namespace]
from graphene import String, ResolveInfo
import graphene
class TestQuery(graphene.ObjectType):
field = graphene.Field(String)
@staticmethod
def resolve_field(_: None, __: ResolveInfo) -> Optional[str]:
return 'hi'
Schema(query=TestQuery)
[out]
Success: no issues found in 1 source file
Using one type as the base class of another is valid in graphene, but it causes an error to be thrown by our plugin.
Minimal repro:
from graphene import ObjectType, String, Field, NonNull
class User(ObjectType):
id = Field(NonNull(String))
class MoreSpecificUser(User):
id = Field(NonNull(String))
It causes a StopIteration
error to be thrown by this code in the plugin:
graphene_base = next(
base for base in type_info.bases if base.type.fullname in (GRAPHENE_OBJECTTYPE_NAME, GRAPHENE_INTERFACE_NAME)
)
According to the graphene documentation, the following is the same:
class Person(graphene.ObjectType):
name = graphene.String()
# Is equivalent to:
class Person(graphene.ObjectType):
name = graphene.Field(graphene.String)
However, graphene-stubs doesn't allow the above example when using resolvers.
from graphene import ObjectType, String
from graphql import ResolveInfo
class Person(ObjectType):
name = String()
@staticmethod
def resolve_name(_, __: ResolveInfo) -> str:
return "Test"
$ mypy test.py
test.py:11: error: No field with name "name" defined
Found 1 error in 1 file (checked 1 source file)
When wrapping it in a Field
it's fine. Is this a known limitation or would this classify as a bug that can be fixed?
Hi!
Is there any context to why the dist/
directory is being versioned?
Normally:
.gitignore
), but there may be some special reason to?.whl
/ .tar.gz
's and they could be built at any time via the git tagThoughts? If they're not needed: I could provide information on what I think you could do
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.