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

feat(Apollo): Expose mutations to the gateway. #7358

Merged
merged 10 commits into from
Jan 27, 2021

Conversation

minhaj-shakeel
Copy link
Contributor

@minhaj-shakeel minhaj-shakeel commented Jan 22, 2021

Fixes GRAPHQL-968.
This PR does two things.
1 - It exposes the mutations to the apollo gateway which were earlier restricted. It exposes mutations for both type definitions as well as type extensions. Whereas queries for the extended types are not exposed as they are resolved through entity resolver.
2 - It adds support for add mutation on extended type having field with ID type as @key field. In this case the field is stored internally in the dgraph as string type so its value needs to be given as an argument inside the mutation.


This change is Reviewable

Copy link
Contributor

@abhimanyusinghgaur abhimanyusinghgaur left a comment

Choose a reason for hiding this comment

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

Nice PR!
:lgtm:

Reviewed 7 of 7 files at r1, 2 of 2 files at r2.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @pawanrawal)

Copy link
Contributor

@pawanrawal pawanrawal left a comment

Choose a reason for hiding this comment

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

Reviewable status: 6 of 9 files reviewed, 5 unresolved discussions (waiting on @abhimanyusinghgaur and @minhaj-shakeel)


graphql/e2e/common/query.go, line 455 at r3 (raw file):

func addMutationOnExtendedTypeWithIDasKeyField(t *testing.T) {
	addAstronautParams := &GraphQLParams{
		Query: `mutation addAstronaut($id1: ID!, $missionId1: String!, $id2: ID!, $missionId2: String! ) {

Do the mission and astronaut with the specified ids already exist in this service?


graphql/resolve/query_rewriter.go, line 263 at r3 (raw file):

	//	}

	// If key field is of ID type but it is an external field,

This comment looks like it belongs in the else block.

So basically if it's not external, then we query using the uid otherwise we treat it as a string and query using eq function.


graphql/schema/gqlschema.go, line 993 at r3 (raw file):

		addFieldFilters(sch, defn, apolloServiceQuery)
		addAggregationResultType(sch, defn)
		// Don't expose queries for the @extends type to the gateway

What about all the other things like filters and such which the query uses. Should they also not be exposed?


graphql/schema/wrappers.go, line 511 at r3 (raw file):

			// If key field is of ID type but it is an external field,
			// then it is stored in Dgraph as string type with Hash index.
			// So we need the predicate mapping in this case.

Can we add a dgraph schema gen test for key field which is an ID but is an external field that shows the type for it in Dgraph schema?


graphql/schema/testdata/apolloservice/output/extended-types.graphql, line 357 at r3 (raw file):

}

input AstronautFilter {

If the astronaut query isn't generated then why do we have AstronautFilter and ORder.

Copy link
Contributor

@pawanrawal pawanrawal left a comment

Choose a reason for hiding this comment

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

Reviewable status: 6 of 9 files reviewed, 2 unresolved discussions (waiting on @abhimanyusinghgaur and @minhaj-shakeel)


graphql/e2e/common/query.go, line 466 at r3 (raw file):

			}
		}`,
		Variables: map[string]interface{}{

Can you add a test where you add a new mission and link to an astronaut that doesn't exist yet? Does that return an error or work properly?

Copy link
Contributor

@pawanrawal pawanrawal left a comment

Choose a reason for hiding this comment

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

Reviewed 6 of 7 files at r1, 3 of 3 files at r3.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @minhaj-shakeel)

Copy link
Contributor Author

@minhaj-shakeel minhaj-shakeel left a comment

Choose a reason for hiding this comment

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

Reviewable status: 6 of 12 files reviewed, 2 unresolved discussions (waiting on @abhimanyusinghgaur and @pawanrawal)


graphql/e2e/common/query.go, line 466 at r3 (raw file):

Previously, pawanrawal (Pawan Rawal) wrote…

Can you add a test where you add a new mission and link to an astronaut that doesn't exist yet? Does that return an error or work properly?

Done that. It creates a new object or links the object if the object with the same xid already exists.


graphql/resolve/query_rewriter.go, line 263 at r3 (raw file):

Previously, pawanrawal (Pawan Rawal) wrote…

This comment looks like it belongs in the else block.

So basically if it's not external, then we query using the uid otherwise we treat it as a string and query using eq function.

Yeah, shifted the comment and modified it.

Copy link
Contributor Author

@minhaj-shakeel minhaj-shakeel left a comment

Choose a reason for hiding this comment

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

Reviewable status: 6 of 12 files reviewed, 2 unresolved discussions (waiting on @abhimanyusinghgaur and @pawanrawal)


graphql/e2e/common/query.go, line 455 at r3 (raw file):

Previously, pawanrawal (Pawan Rawal) wrote…

Do the mission and astronaut with the specified ids already exist in this service?

No, both don't exist. If the mission exists, it will throw an error and if the Astronaut exists then it will just link the previous object the newly created mission object.


graphql/schema/gqlschema.go, line 993 at r3 (raw file):

Previously, pawanrawal (Pawan Rawal) wrote…

What about all the other things like filters and such which the query uses. Should they also not be exposed?

These are being exposed. See the schemagen/apolloservice tests.


graphql/schema/wrappers.go, line 511 at r3 (raw file):

Previously, pawanrawal (Pawan Rawal) wrote…

Can we add a dgraph schema gen test for key field which is an ID but is an external field that shows the type for it in Dgraph schema?

Those are already added in the federation branch.


graphql/schema/testdata/apolloservice/output/extended-types.graphql, line 357 at r3 (raw file):

Previously, pawanrawal (Pawan Rawal) wrote…

If the astronaut query isn't generated then why do we have AstronautFilter and ORder.

For AddAstronautPayload.

Copy link
Contributor

@pawanrawal pawanrawal left a comment

Choose a reason for hiding this comment

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

Reviewed 6 of 6 files at r4.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @minhaj-shakeel)

@minhaj-shakeel minhaj-shakeel merged commit 1a74997 into minhaj/apollo-federation Jan 27, 2021
@minhaj-shakeel minhaj-shakeel deleted the minhaj/fix-mutation branch January 27, 2021 06:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants