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

allow custom directives #53

Open
ngmariusz opened this issue Feb 22, 2019 · 11 comments

Comments

@ngmariusz
Copy link

commented Feb 22, 2019

if i understand correctly there is only @deprecated possible so far? it there way to add custom ones?
tools out there usually depend on custom directives then i could integrate nexus into toolchain

@tgriesser

This comment has been minimized.

Copy link
Collaborator

commented Feb 22, 2019

We can add the ability to define a directive for runtime use, but (as far as I can tell) adding them for use annotating the SDL would be more difficult, due to lack of support in graphql-js:

Can you talk more about the type of directives you are looking to add and how they would be used?

@tgriesser tgriesser added the question label Feb 22, 2019

@ngmariusz

This comment has been minimized.

Copy link
Author

commented Feb 25, 2019

Sure,

So Basically my question was motivated with context the of trying to use Nexus in already existing Project or pipeline (which is schema first)
Let’s say i have a set of custom directives syntax that i use to annotate schema and then parse with my cli tools to generate resolvers, db and so on
As Nexus actually generates schema i’ll put it on the beginning of tool chain try to achieve same result as i would write by hand in my .graphql files.
So finally i would just like to be able to achive in exp this

type User @entity {
  id: ID! @id
  email: String! @column @map(path: "login.email") @depreciated(reason: 'lorem')
}

with sth like

const User = objectType({
 annotate:'@entity',
 name: 'User',
 definition(t) {
   t.string('email', { annotate:'@column @map(path: "login.email")', deprecation: 'lorem', nullable: true });
   t.id('id', { annotate:'@column' })
 }
});

i understand that will be implementing workaround (until it's figured out in graphql-js) perhaps by repacing
printSchema in generateSchemaFile with graphql/graphql-js#869 (comment)

without this feature switching to Nexus seems like I have to leave behind everything that already works

@tgriesser

This comment has been minimized.

Copy link
Collaborator

commented Mar 4, 2019

I think this should be possible to add, going to dig into what it'll take to do this properly and keep you posted.

@tgriesser tgriesser added enhancement and removed question labels Mar 4, 2019

@jregistr

This comment has been minimized.

Copy link

commented Apr 3, 2019

👋 Hellos! I'm also interested in this. Perhaps all we'd need for implementing this is the ability to specify directives for type and field creation?
At a glance, looks like one can use apollo's graph-tools to make the schema while providing directives.

@tgriesser

This comment has been minimized.

Copy link
Collaborator

commented Apr 3, 2019

👋

Perhaps all we'd need for implementing this is the ability to specify directives for type and field creation? At a glance, looks like one can use apollo's graph-tools to make the schema while providing directives.

Yes - you can add these in graphql-tools, but It's not quite as simple to do programmatically because they needed to be added to the AST for the schema, which is possible but takes a bit more work.

I've started work on it in this branch, it's something I plan on getting to but it still needs quite a bit of work to get the type generation, etc working properly.

@tgriesser

This comment has been minimized.

Copy link
Collaborator

commented Apr 4, 2019

Actually this looks like it might also be simple to do programmatically extendSchema, will take a look into that approach.

@trufa

This comment has been minimized.

Copy link

commented May 13, 2019

Any news on this?

@Mika83AC

This comment has been minimized.

Copy link

commented May 25, 2019

I'd also urgently need custom directives in nexus for applying authorization on query and field levels without highly repetetiv code in all resolvers.

@Schubidu

This comment has been minimized.

Copy link

commented Jun 21, 2019

Any news about directives. I want to use Apollo Federation and I need to use directives on nexus.

@Schubidu

This comment has been minimized.

Copy link

commented Jun 21, 2019

Oh I just found a related issue #148

@jhalborg

This comment has been minimized.

Copy link

commented Jul 18, 2019

Also relevant for caching with Apollo Server. We are trying to map out what it would take for us to migrate from graphql-js to nexus, and this feature is a blocker as we are quite reliant on directives on our platform

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants
You can’t perform that action at this time.