Giter VIP home page Giter VIP logo

Comments (1)

Maximilien-R avatar Maximilien-R commented on September 24, 2024

After internal discussions, we'll propose a new API regarding hook directives. This will result into significant break changes.

Here is the diff regarding existing hook:

@Directive("myDirective")
class MyDirective:
    @staticmethod
-    async def on_argument_execution(
+    async def on_post_argument_coercion(
        directive_args,
        next_directive,
        parent_node,
        argument_definition_node,
-        argument_node,
        value,
        ctx,
    ):
        pass

    @staticmethod
    async def on_post_input_coercion(
        directive_args,
        next_directive,
        parent_node,
+       input_definition_node,
        value,
        ctx,
    ):
        pass

The on_argument_execution has been renamed into on_post_argument_coercion to gain clarity and consistency with hooks of the same order. Its method prototype has changed too, we'll drop the argument_node parameter which isn't really useful.

Also, the on_post_input_coercion method prototype has been changed too, we'll add the input_definition_node parameter which will contains the input definition node of the coerced value (Union[InputObjectTypeDefinitionNode, InputValueDefinitionNode, ScalarTypeDefinitionNode, EnumValueDefinitionNode]).

In addition to those changes, we'll provide new hooks for each kind of node. This way, it will be possible to be more granular in the implementation of directives depending to the type of node.

Here are the new hooks which will be available:

@Directive("myDirective")
class MyDirective:
+    @staticmethod
+    async def on_post_input_object_coercion(
+        directive_args,
+        next_directive,
+        parent_node,
+        input_object_type_definition: InputObjectTypeDefinitionNode,
+        value,
+        ctx,
+    ):
+        pass


+    @staticmethod
+    async def on_post_input_field_coercion(
+        directive_args,
+        next_directive,
+        parent_node,
+        input_field_definition: InputValueDefinitionNode,
+        value,
+        ctx,
+    ):
+        pass

+    @staticmethod
+    async def on_post_scalar_input_coercion(
+        directive_args,
+        next_directive,
+        parent_node,
+        scalar_definition: ScalarTypeDefinitionNode,
+        value,
+        ctx,
+    ):
+        pass

+    @staticmethod
+    async def on_post_enum_type_input_coercion(
+        directive_args,
+        next_directive,
+        parent_node,
+        enum_type_definition: EnumTypeDefinitionNode,
+        value,
+        ctx,
+    ):
+        pass

+    @staticmethod
+    async def on_post_enum_value_input_coercion(
+        directive_args,
+        next_directive,
+        parent_node,
+        enum_value_definition: EnumValueDefinitionNode,
+        value,
+        ctx,
+    ):
+        pass

With those new hooks we should cover every case of post input coercions, meaning that the on_post_input_coercion hook could have no utility anymore but that's not the case. The on_post_input_coercion hook will be use as fallback/generic hook for each type. It means that, if you have a common use-case for each type you can implement the on_post_input_coercion hook instead of implementing each hooks. Also, you can implement the on_post_input_coercion hook and some other specific type hook if you want a specific behavior for those types. This way, we'll allow both flexibility and granurality regarding post input coercion hooks 👍

In addition to the post input coercion hooks, we'll think to do the same on the pre_output_coercion one.

from tartiflette.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.