Skip to content
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

Resolver directives continuation #529

Merged
merged 29 commits into from
Dec 12, 2017
Merged

Resolver directives continuation #529

merged 29 commits into from
Dec 12, 2017

Conversation

stubailo
Copy link
Contributor

@stubailo stubailo commented Dec 12, 2017

#518 continuation

TODO:

  • If this PR is a new feature, reference an issue where a consensus about the design was reached (not necessary for small changes)
  • Make sure all of the significant new logic is covered by tests
  • Rebase your changes on master so that they can be merged easily
  • Make sure all tests and linter rules pass
  • Update CHANGELOG.md with your change

@stubailo
Copy link
Contributor Author

stubailo commented Dec 12, 2017

@giautm opened a new PR so we can both push to the same one; I invited you to be a contributor! https://github.com/apollographql/graphql-tools/invitations

I'm going to rename directiveResolvers to resolverDirectives since these are "directives that apply to resolvers"

Never mind. I do think the directive should be on FIELD_DEFINITION though according to this: https://github.com/facebook/graphql/pull/90/files#diff-c9d195396161bb690c5fd8899af11d78R280

@stubailo stubailo merged commit cc69bb1 into master Dec 12, 2017
@gregberge
Copy link

@giautm thanks for your work! @stubailo thanks for merging it!

I found several problems in the current implementation:

  • Using directives in query is not supported
  • We do not have any error if resolver is not defined
  • We do not check if directive has the location "FIELD_DEFINITION"
  • The naming is not consistent with existing API (addResolveFunctionsToSchema != attachDirectiveResolvers, it should be addDirectiveResolveFunctionsToSchema)

I fixed all of these issues in a separated package: graphql-directive.

If we want Apollo Client to be compatible with directives in query we need to merge this PR. It fixes a cache issue.

I think we could improve the current function by using graphql-directive implementation.

What do you think?

@giautm
Copy link
Contributor

giautm commented Dec 13, 2017

Hi @neoziro, there is my response:

  • Maybe in the next PR. It's not a problem.
  • An FIELD_DEFINITION directive maybe change the field meta info like @deprecated. So it doesn't need to have a resolver function.
  • Maybe directives in another location can have a resolver too. So I don't check the location.
  • attachDirectiveResolvers maybe rename to addDirectiveResolveFunctionsToSchema if @stubailo agree.
● addDirectiveResolveFunctionsToSchema › FIELD (schema) › should throw an error if resolver is not defined

    Directive @deprecated has no resolver.Please define one using createFieldExecutionResolver().

Yep, your test throws an error for built-in directives.

PS: I don't understand why you did not contribute to #518 while waiting to merge rather than creating a new module?

@gregberge
Copy link

@giautm thanks!

I have to fix it for @deprecated, I think we could not throw it for "deprecated" and only for others. Built-in directives are well-known and it is easy to maintain a white-list.

I did not contribute to #518 because I wanted to experiment and try it before merging it in this project. grahpql-tools is massively used and I want to be sure it is good before adding a new feature in this project. Also, I will talk about this in a Meetup and I wanted it to be public and usable before my talk.

@giautm
Copy link
Contributor

giautm commented Dec 13, 2017

Built-in directives are well-known and it is easy to maintain a white-list.

No, I don't think it's a good idea. Because there are a lot of directives from User if they want to add new. Your module will block them to do that. (by throwing an error).

@gregberge
Copy link

@giautm I am not sure. I think most of people are not using directives at all and it makes it easier to have a coherent setup. Do you know some projects that are already using custom directives?

@stubailo
Copy link
Contributor Author

I did not contribute to #518 because I wanted to experiment and try it before merging it in this project. grahpql-tools is massively used and I want to be sure it is good before adding a new feature in this project. Also, I will talk about this in a Meetup and I wanted it to be public and usable before my talk.

Please don't feel that this means we have to move slowly! I think as long as the feature isn't documented we can keep working on changing it. I'll add something to it that says "experimental" for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants