Skip to content

Ability to add our own directives #151

@renoirb

Description

@renoirb

May be related to #116.

CONTEXT

Author of this request is proficient JavaScript, but not in Go. Some statements in this issue may skewed perceptions based as a total beginner in Go.

REQUEST/QUESTION

Assuming we have a schema that supports Time scalar (like you've done in TestTime), and we want to use a custom formatter using GraphQL directives.

Is there plans for our own neelance/graphql-go GraphQL server implementation to create our own directives?

For example, we could get a n days ago, by defining our own @date(...) directive;

query {
  ago: addHour("2001-02-03T04:05:06Z") @date(as: "days ago")
}
// => { "ago": "6189 days ago" }

I'm aware not all types of Directives would be useful to ALL packages extending neelance/graphql-go.

It wouldn't make sense to have scalar Time exported by default.

But what I enjoyed in tests/, and the file time.go, was that I could see how I could implement my own scalar.

That would be awesome to have another example where one could see how to implement properly his own directive (e.g. @date).

OBSERVATIONS

As said in #116, it looks like the place we could append our own directives would be implemented are hidden away. I assume it's because lowerCased functions aren't exported in Go.

I see in internal/exec/selected/selected.go at line 194 how you’ve implemented @skip directive

And also how (black magic?) you’ve implemented @onQuery at internal/tests/testdata/tests.json {"schemas": []}, and ran from internal/tests/all_test.go TestAll

LINKS

Maybe you'd like to see some directives implemented in JavaScript, here is one implementation sample I found useful; lirown/graphql-custom-directives Date Formatting Directives

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions