Skip to main content

Ariadne 0.7.0

· 3 min read

Ariadne 0.7 brings support for custom schema directives and synchronous extensions.

Custom schema directives

In SDL, schema directives act as annotations adding extra information and meaning to schema's items. Ariadne already supported the @deprecated directive described by the specification and enabled developers to declare custom directives in schema with directive @example on syntax, but until now there was no obvious and easy way for developers to implement behavior for those:

directive @requireRole(role: Role!) on FIELD_DEFINITION

enum Role {
USER
MODERATOR
}

type Query {
reportedContent: [Posts!] @requireRole(role: MODERATOR)
}

Ariadne 0.7 provides the SchemaDirectiveVisitor type that is associated with specified annotation in schema by developer, and can be used to perform changes in the schema like wrapping annotated fields resolvers with custom one:

class RequireRoleSchemaDirective(SchemaDirectiveVisitor):
def visit_field_definition(self, field, object_type):
role = self.args.get("role")
original_resolver = field.resolve or default_field_resolver

def resolve_with_role_check(obj, info, **kwargs):
if role not in info.context["roles"]:
return None

return original_resolver(obj, info, **kwargs)

field.resolve = resolve_with_permission_check
return field

I'm also very happy to add that custom schema directives implementation is a contribution from Yasin Bahtiyar. Thank you!

Synchronous extensions

Ariadne 0.6 released with support for extensions, but those were only implemented for asynchronous servers (running with ASGI). Thanks to contribution by Daniel Rice, Ariadne now also supports extensions in WSGI servers, and the documentation has been updated accordingly. We've also added synchronous versions of Apollo trace and OpenTracing extensions.

We've also updated existing extensions API, making context available to has_errors and format hooks.

Hacktoberfest

Hacktoberfest 2019 is underway, and we are participating! Make sure you check Ariadne's issue tracker for issues labeled with "hacktoberfest" if you want to help!

GraphQL federations

We would like to use this opportunity to also give a shout out to Ales Zoulek, who has implemented GraphQL federations support for Ariadne.

Federations are latest hotness in the GraphQL world - they provide a way to combine multiple GraphQL APIs into one. We would love for Ariadne to provide out-of-the box support for this, but getting such a feature to a state when it can be included to library's codebase is a considerable task.

You can help! Test federation in your projects, report issues and contribute bugfixes and tests!

CHANGELOG

  • Added support for custom schema directives.
  • Added support for synchronous extensions and synchronous versions of ApolloTracing and OpenTracing extensions.
  • Added context argument to has_errors and format hooks.