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: added Description() for adding meta data to a field #364

Merged
merged 9 commits into from
Aug 17, 2022

Conversation

Albert-Gao
Copy link
Contributor

No description provided.

Copy link
Member

@a8m a8m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution @Albert-Gao.

The next thing is to add it to the gqlparser/ast.Definition.

@Albert-Gao
Copy link
Contributor Author

@a8m thanks for the comments, how to do this please? I checked the file, but do not know how to link the added the field to this FieldConfig.Descrption. What I am missing here please? Thanks :)

@giautm
Copy link
Collaborator

giautm commented Aug 15, 2022

Hello @Albert-Gao, you need to add def.Description to this block of code. It's our query field on the Query Object.

contrib/entgql/schema.go

Lines 208 to 231 in a1f3cb4

if ant.RelayConnection {
if !e.relaySpec {
return ErrRelaySpecDisabled
}
s.AddTypes(names.TypeDefs()...)
if ant.QueryField != nil {
name := ant.QueryField.fieldName(gqlType)
_, hasOrderBy := s.Types[names.Order]
hasWhereInput := e.genWhereInput && !ant.Skip.Is(SkipWhereInput)
def := names.ConnectionField(name, hasOrderBy, hasWhereInput)
def.Directives = e.buildDirectives(ant.QueryField.Directives)
queryFields = append(queryFields, def)
}
} else if ant.QueryField != nil {
name := ant.QueryField.fieldName(gqlType)
def := &ast.FieldDefinition{
Name: name,
Type: listNamedType(gqlType, false),
}
def.Directives = e.buildDirectives(ant.QueryField.Directives)
queryFields = append(queryFields, def)
}

The latest thing, don't forget to merge annotation if we have more than one on the entity:

func (c *FieldConfig) merge(ant *FieldConfig) {
if ant == nil {
return
}
if ant.Name != "" {
c.Name = ant.Name
}
c.Directives = append(c.Directives, ant.Directives...)
}

@Albert-Gao
Copy link
Contributor Author

Albert-Gao commented Aug 15, 2022

Thanks, @giautm added, please check.

@@ -90,7 +90,7 @@ func (Todo) Edges() []ent.Edge {
func (Todo) Annotations() []schema.Annotation {
return []schema.Annotation{
entgql.RelayConnection(),
entgql.QueryField(),
entgql.QueryField().Description("This the todo item"),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not quite sure how to test the outcome of this, when running the tests locally, I have an error and do not know how to solve it.

image

entgql/annotation.go Outdated Show resolved Hide resolved
entgql/annotation.go Outdated Show resolved Hide resolved
Albert-Gao and others added 2 commits August 16, 2022 21:37
Co-authored-by: Ariel Mashraki <7413593+a8m@users.noreply.github.com>
@Albert-Gao
Copy link
Contributor Author

Albert-Gao commented Aug 16, 2022

image

Why this test is failing locally? 🤣
anyway, fixed the test of the updated schema

entgql/annotation.go Outdated Show resolved Hide resolved
entgql/annotation.go Outdated Show resolved Hide resolved
@giautm giautm force-pushed the add-desc-to-gql-gen branch from 3051d9f to bee18da Compare August 17, 2022 07:56
@giautm giautm merged commit febe8f2 into ent:master Aug 17, 2022
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.

3 participants