Comments (8)
Perhaps scalars could accept everything directly in the class initializer?
from ariadne.
For API consistency we should also update the Enum
implementation to let you create enum via set_items
perhaps.
from ariadne.
Shouldn't the enum also accept all of its attributes in the constructor? Compare:
foo = Enum("Foo")
foo.set_items(something)
# vs.
foo = Enum("Foo", something)
from ariadne.
Slightly related: should we warn if you try to set items/resolver/source/whatever of the same type for a second time using the same bindable instance?
from ariadne.
Shouldn't the enum also accept all of its attributes in the constructor? Compar
This is correct, and its already the case with our Enums.
Likely we should update Scalar
to accept three kwargs
in addition to decorators.
The question is if there are scenarios out there for using procedural API for setting scalar resolvers, ergo:
foo = Scalar("test")
foo.set_serializer(my_serializer)
This looks good on the surface, but what possible uses are there for it?
Slightly related: should we warn if you try to set items/resolver/source/whatever of the same type for a second time using the same bindable instance?
Yup, missing the resolver on field can lead to tricky bugs. We should signalize to the dev if such situations happen.
from ariadne.
I've decided to sit down and put together the draft for API change:
ResolverMap
foo = ResolverMap("Name")
# decorator syntax
@foo.field("name")
def resolve_name(*_):
...
# setter syntax
foo.set_alias("name", "attr_name")
foo.set_field("name", resolve_name)
foo.set_source("name", observe_name)
Scalar
Decorator syntax:
foo = Scalar("Name")
@foo.serializer
def serialize_foo(*_):
...
@foo.value_parser
def parse_foo_value(*_):
...
@foo.literal_parser
def parse_foo_literal(*_):
...
Constructor syntax:
foo = Scalar(
"Name",
serializer=serialize_foo,
value_parser=parse=parse_foo_value,
literal_parser=parse_foo_literal,
)
Perhaps we should rollback to GraphQL's serialize
, parse_value
and parse_literal
for constructor kwargs?
Enum
foo = Enum("Name", enum_or_dict)
Union
Constructor syntax:
foo = Union("Name", type_resolver)
Decorator syntax:
foo = Union("Name")
@foo.type_resolver
def resolve_union_type(*_):
...
from ariadne.
For what it's worth, I would be strongly in favor of the constructor-only API.
Procedural APIs may seem convenient, but my experience is that by empowering any code that has a reference to an object to modify it, developers are often tempted into difficult-to-follow code patterns.
from ariadne.
We could work around what you are mentioning by raising warning or error when user changes previously set resolver. We already have some of those in place - our bindables already raise ValueError if name is not found in schema, or types don't match.
from ariadne.
Related Issues (20)
- Feature request: cache query parsing and validation HOT 10
- Breaking changes to Extension not noted in 0.20 changelog HOT 6
- Reference resolver HOT 2
- GraphiQL is not rendering (Explorer plugin error)
- Custom JSON implementation HOT 2
- Cannot install 0.15 HOT 2
- Expose all graphiql parameters HOT 1
- Union as directive argument HOT 4
- No way to send custom error from `on_connect` when using GraphQLTransportWSHandler
- execution_context_class argument for graphql_sync raises an error HOT 4
- Subscription Chat Application full example does not return message data HOT 2
- "str" is incompatible with "GraphQLSchema" HOT 2
- Update GraphQL fixing logic
- Python 3.12 has deprecation warnings
- Starlette integration tests are broken
- Re-tag the source HOT 1
- Ariadne `graphql` and `graphql_sync` will attempt to execute `subscription` operations
- Return data and errors from root resolver callable
- Update GraphiQL version
- Interface resolver issues with Pydantic schemas HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ariadne.