Comments (11)
I'd propose to drop fields
parameter from strawberry_django.field
if we decide to go with class-oriented API.
Is anyone against that?
from strawberry-django.
oh, also do we need:
@strawberry_django.query @strawberry_django.mutation
No we do not need them. I was drafting something, then throw it away and forgot to update. :)
from strawberry-django.
I don't dislike this, my only concert is that might be a bit more confusing than a fields
argument (as you'd do on django rest framework and django forms)
the other thing, should consider a way of automatically exposing all the fields? 🤔
/cc @BryceBeagle @jkimbo
from strawberry-django.
oh, also do we need:
@strawberry_django.query
@strawberry_django.mutation
?
it sounds like we could use @strawberry.type
directly
from strawberry-django.
Good idea IMO. Easier to read, because user doesnt have to add the fields passed to strawberry_django.type
and the declared class fields together to see what fields are available.
Imagine changelog for adding description.
Old api:
@strawberry_django.type(models.User, fields=("id", "name", ))
class User:
pass
to
@strawberry_django.type(models.User, fields=("name", ))
class User:
id: strawberry.ID = ...
or new API
@strawberry_django.type(models.User)
class User:
id: auto
name: auto
to
@strawberry_django.type(models.User)
class User:
id: auto = ...
name: auto
But the pro of the old API is, you can do something like this:
readonly_fields = (...)
update_fields= (...)
@strawberry_django.type(models.User, fields=(*readonly_fields, *update_fields))
class UserType:
pass
@strawberry_django.input(models.User, fields=update_fields)
class UserUpdate:
pass
from strawberry-django.
But the pro of the old API is, you can do something like this:
readonly_fields = (...) update_fields= (...) @strawberry_django.type(models.User, fields=(*readonly_fields, *update_fields)) class UserType: pass @strawberry_django.input(models.User, fields=update_fields) class UserUpdate: pass
You can generate dataclasses like this
dataclasses.make_dataclass('UserUpdate', fields)
Or use class inheritance
class ReadOnlyFields:
...
class UpdateFields:
...
@strawberry_django.type(models.User)
class UserType(ReadOnlyFields, UpdateFields):
pass
@strawberry_django.input(models.User)
class UserType(UpdateFields):
pass
from strawberry-django.
We are currently working on that. Code is still under development but it's already available in https://github.com/strawberry-graphql/strawberry-graphql-django/tree/feature/class-api branch if someone wants to take a look or try it :)
from strawberry-django.
https://www.python.org/dev/peps/pep-0647/ has the notion of type guards. Getting this done via static type checkers seems preferable over writing validators.
Having said that it's not clear that the PEP above has enough to specify all the constraints needed.
from strawberry-django.
https://www.python.org/dev/peps/pep-0647/ has the notion of type guards. Getting this done via static type checkers seems preferable over writing validators.
Having said that it's not clear that the PEP above has enough to specify all the constraints needed.
Do you have example how this could be used with class oriented API?
from strawberry-django.
It's not clear that this feature is usable by end users just yet. It seems to be designed for type checkers like mypy/pyright. Someone on python discord was speculating about implementing refinement types using TypeGuards.
The specific example discussed was:
from dataclasses import dataclass
from typing import Any, Optional, TypeGuard
class LessThan10(float):
pass
def is_LessThan10(x: float) -> TypeGuard[LessThan10]:
return x < 10.0
@dataclass
class Thing:
x: LessThan10
y: float
I would like a type checker to be able to detect that Thing(20, 1) is a type error.
@erictraut would know, but I'm not sure if I can tag him here.
from strawberry-django.
This will be part of v0.2 release. See pull request #30. Let's continue discussion there.
from strawberry-django.
Related Issues (20)
- Enum values in mutation input causes ValidationError HOT 2
- Allow to return custom types on mutations without a related django model
- Self is coroutine - there is no data being awaited. HOT 4
- Nested Perms Results in unecessary queries (N+1?) HOT 4
- Built in create mutation has regressed and is not able to create model instances correctly HOT 2
- `django.db.models.expressions.DatabaseDefault` raises `TypeError: fromisoformat` on mutation HOT 1
- Docs for reference for DjMoney type HOT 5
- ForeignKey `_id` field resolves to relation object, not field value HOT 8
- Returning `bool` from mutation causes exception. HOT 6
- Custom filter/order method unexpected value
- ListConnectionWithTotalCount and filter custom resolver HOT 2
- description and deprecation_reason parameters of enums values not used HOT 4
- Apollo Sandbox doesn't update debug toolbar HOT 2
- Ability to use custom StrawberryDjangoField class for relay connections and nodes HOT 1
- Slow startup when defining many filters HOT 5
- N+1 in some resolvers when enabling `only` extension HOT 2
- The right way to protect and filter information HOT 5
- Thanks! HOT 1
- The get_queryset method is called twice when using relay connections HOT 1
- Custom ordering methods doesn't work when value are passed by variables HOT 1
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 strawberry-django.