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

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

simon-wenmouth
Copy link

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.

@simon-wenmouth
Copy link
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.

@simon-wenmouth simon-wenmouth force-pushed the feature/protoc-gen-entgql branch from fcc8576 to 06342a4 Compare July 16, 2024 04:40
@simon-wenmouth
Copy link
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.
@simon-wenmouth simon-wenmouth force-pushed the feature/protoc-gen-entgql branch from 06342a4 to d82c1b6 Compare July 16, 2024 05:12
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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant