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

entgql: possibility to attach custom directives to mutation create and update inputs #3407

Open
1 task done
lucvankessel opened this issue Mar 23, 2023 · 5 comments · May be fixed by ent/contrib#612
Open
1 task done
Labels

Comments

@lucvankessel
Copy link
Contributor

I want to attach a custom directive to a generated mutation create/update field.

  • I have searched the issues of this repository and believe that this is not a duplicate.

Summary 💡

Through the mutations in a field definition in a schema i want to be able to do something like entgql.UpdateMutation.Directive('directive name', {args}) to be able to attach the given directive to it. (using the same syntax as the current way to add directives to the gql type would be preffered)

Motivation 🔦

Right now i can create a custom directive for checking the minimum length of a string(for example). but this directive is executed whenever i get a object from the database and not when i insert one through a create/update input.
This leads to me being unable to attach directives to places i want them on. manually this would be possible but we generate our create and update inputs through the mutations and want to attach them in the schema/field definitions.

@lucvankessel
Copy link
Contributor Author

See the merge request above for the fix i wanted.
In there i also added a question about adding the skipping of adding directives to certain types/field/mutations.

@a8m
Copy link
Member

a8m commented Mar 24, 2023

Hey, @lucvankessel 👋
Would you mind putting here an example of the mutation inputs you want to generate with entgql? Are these input directives or field-level directives?

Just to make sure you're not blocked on this, check out my SchemaHook example at: #3173 (comment)

@lucvankessel
Copy link
Contributor Author

lucvankessel commented Mar 25, 2023

hey @a8m,
This is a simple example of what i want:

input CreateProjectInput {
  name: String! @CustomDirective("some arg")
}

This input is then generated from the mutations in the schema.
Right now i can generate the inputs without the directive through the mentioned mutations annotation.
This MR does what i want it to do.
In the future it might also be nice to have the ability to skip these directives on either the type, create or update inputs through the SkipMode that is already used to skip certain fields from being added to these generated inputs.

(i havent tested it yet but, )I dont think the use of SchemaHooks will work in this case due to mutation fields having the directives field used when generating them. In buildMutationInputs in schema.go this is the current field definition:

def.Fields = append(def.Fields, &ast.FieldDefinition{
				Name:        camel(f.Name),
				Type:        namedType(scalar, f.Nullable),
				Description: f.Comment(),
			})

So directives are never added to them to be able to be generated (or atleast that seems to be the case from what i read, i do not know the entire flow of generating fields in entgql yet so i can be terribly wrong ofcourse)

Hope this answers your question.

@lucvankessel
Copy link
Contributor Author

Hey @a8m,
Can i help you guys in any way to fast track the progress on this issue?

@lucvankessel
Copy link
Contributor Author

Made this [MR]{https://github.com/ent/contrib/pull/543} a few days ago with a proposed backwards compatible solution. let me know what you think and if it needs changing etc.

@danicc097 danicc097 linked a pull request Jan 27, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants