-
Notifications
You must be signed in to change notification settings - Fork 179
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
Implement GraphQL modules #306
Comments
I've had short brainstorming session with @patrys about this, and initial idea is to introduce new base class that's basically type definition + requirements + resolvers, something like this: class User(ObjectType[models.User]):
# Validated to contain exactly single type declaration
__schema__ = gql(
"""
type User {
id: ID!
name: String!
email: String
group: UserGroup!
joinedAt: DateTime!
lastVisit: DateTime
}
"""
)
# Optional, allows mapping fields to resolver functions in python
# if mapping is defined here but function is not declared on class, it will be autogenerated
__resolvers__ = {
"joinedAt": "joined_at",
"lastVisit": "last_visit",
}
# Optional, list of other GraphQL types/objects this type requires
__requires__ = [UserGroup]
# Resolvers methods
@staticmethod
def email(obj, info) -> Optional[str]:
if can_see_email(info.context, obj):
return obj.email
return None
@staticmethod
def last_visit(obj, info) -> Optional[datetime]:
if can_see_activity(info.context, obj):
return obj.last_visit
return None We could implement additional type checks in this class, eg. we could have |
I've created feature branch where I'm experimenting on this implementation: new-object-api My plan is to keep iterating on to get into somewhat working stage for queries, mutations and scalars. When that gets somewhat useable I would like to start including |
I've moved modules implementation to ariadne-graphql-modules library. There was already single release of that lib to PYPI, but it will be broken until Ariadne 0.15 is released. |
Closing this issue. Dev on GraphQL modules for Ariadne will continue in |
GraphQL Modules are a JavaScript tool that allows types and resolvers to be grouped together into functional blocks that depend on each other. Modules can be composed to build larger parts, ultimately leading to a module that represents the entire application.
Importing a single module is easier than importing a list of types, resolvers, and any dependant types or resolvers. Modules are also a straightforward way to implement a code-first declarative interface like that offered by Strawberry. We could also provide tooling to build modules from Graphene and Strawberry objects.
The text was updated successfully, but these errors were encountered: