Skip to content

Navigation Menu

Sign in
Sign up

protoc-gen-ent: support entgql.Annotation - #592

Open
simon-wenmouth wants to merge 2 commits into
ent:master from
simon-wenmouth:feature/protoc-gen-entgql
Open

protoc-gen-ent: support entgql.Annotation #592
simon-wenmouth wants to merge 2 commits into
ent:master from
simon-wenmouth:feature/protoc-gen-entgql

Conversation

@simon-wenmouth

@simon-wenmouth simon-wenmouth commented Jul 16, 2024

Copy link
Copy Markdown

Added support for entgql.Annotation to the protoc-gen-ent plugin. It should now be possible to generate an Ent schema and its GraphQL configuration from a Protocol Buffer file.

The opts.proto was updated adding GQL child MessageTypes to the existing MessageTypes (Schema, Field, Edge). The associated generated code (opts.pb.go) was regenerated using protoc-gen-go.

The AST generation code in schemaast/annotation.go was updated to know about the entgql annotations. The new method attempts to generate code similar to that in the documentation.

The main package was updated to map the configuration settings in the updated opts.proto to the corresponding annotations for the schema, fields, and edges.

Copy link
Copy Markdown
Author

It looks like I should regenerate the opts.pb.go using protoc-gen-go@v1.28.0 and protoc@v3.19.4. I'll update the PR in case this introduces a breaking change for others.

Copy link
Copy Markdown
Author

I've updated the version of protoc to match the previous generated version (only a comment changed).

Added support for `entgql.Annotation` to the `protoc-gen-ent` plugin.
It should now be possible to generate an Ent schema and its GraphQL
configuration from a Protocol Buffer file.
The `opts.proto` was updated adding `GQL` child MessageTypes to the
existing MessageTypes (`Schema`, `Field`, `Edge`). The associated
generated code (`opts.pb.go`) was regenerated using `protoc-gen-go`.
The AST generation code in `schemaast/annotation.go` was updated to know
about the `entgql` annotations. The new method attempts to generate
code similar to that in the documentation.
The main package was updated to map the configuration settings in the
updated `opts.proto` to the corresponding annotations for the schema,
fields, and edges.
When a GraphQL type extends a definition in another sub-graph the names
of the pagination types clash, in particular the where-inputs. Rather
than taking the union of the properties when creating the supergraph, it
takes the common properties. This is true whether your input types are
declared with `type` or `extend type` (or so it seems). It doesn't make
sense to copy-paste the where-input types between projects, since Ent
cannot use them (would mean joining across databases).
This commit allows the rename of the pagination types, avoiding the
clash described above. The feature is used as follows:
	entgql.PaginationNameOverrides = map[string]string{
		"Domain1_EntityA": "DomainN_Domain1_EntityA",
		"Domain2_EntityA": "DomainN_Domain2_EntityB",
	}
In this example, our sub-graph (DomainN) is providing type extensions
for entities in two different sub-graphs (Domain1, Domain2). In this
manner, we will not get collisions when multiple sub-graphs extend a
particular type.
This is combined with a `entgql.WithOutputWriter` that uses a fork of
`github.com/vektah/gqlparser/v2@v2.5.20/formatter/formatter.go` that
overrides `FormatSchema` to accept a set of extension types.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

1 participant

AltStyle によって変換されたページ (->オリジナル) /