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

Converted an extended operation type to a root type in the GraphQL schema #4894

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

Conversation

suyeon-jung-dev
Copy link
Contributor

@suyeon-jung-dev suyeon-jung-dev commented Sep 19, 2024

Proposed changes

I converted an extended operation type to a root type in the GraphQL schema for the following 3 reasons:

  1. Initially, this PR included root Query, Mutations, and Subscriptions. See PR #3602.
  2. According to the GraphQL specification, all three operations require root operations to fulfill our intended purposes. See GraphQL specification

The query root operation type must be provided and must be an Object type.

The mutation root operation type is optional; if it is not provided, the service does not support mutations. If it is provided, it must be an Object type.

Similarly, the subscription root operation type is also optional; if it is not provided, the service does not support subscriptions. If it is provided, it must be an Object type.

According to the GraphQL specification, a schema must define the root operation types for each kind of operation it supports: queries, mutations, and subscriptions. This implies that there must be a clear starting point for executing any operation in the schema.

  1. Also. Without root types, there would be no structured way to initiate queries or mutations, this graphql server could lead to the GraphQL server rendering the schema ineffectively.

I believe this change will ensure that our schema adheres to the GraphQL specifications, potentially improving compatibility and maintainability.

Resolve #4893

Types of changes

What types of changes does your code introduce to Litmus? Put an x in the boxes that apply

  • New feature (non-breaking change which adds functionality)
  • Bugfix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices applies)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I have read the CONTRIBUTING doc
  • I have signed the commit for DCO to be passed.
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • I have added necessary documentation (if appropriate)

Dependency

  • Please add the links to the dependent PR need to be merged before this (if any).

Special notes for your reviewer:

@Saranya-jena
Copy link
Contributor

@suyeon-jung-dev can you please confirm if you have tried running the gqlgen command and it's running fine? go run github.com/99designs/gqlgen generate

@suyeon-jung-dev
Copy link
Contributor Author

suyeon-jung-dev commented Sep 20, 2024

@suyeon-jung-dev can you please confirm if you have tried running the gqlgen command and it's running fine? go run github.com/99designs/gqlgen generate

Hi @Saranya-jena

I refactored root types to Query and Mutation in chaos_experiment.graphqls to ensure no changes during gqlgen build.

I've attached the gqlgen generate results below.

image

And, I'll include the changes in generated.go.
image

…os_experiment.graphqls for gqlgen compatibility

Signed-off-by: Suyeon Jung <[email protected]>
@suyeon-jung-dev
Copy link
Contributor Author

suyeon-jung-dev commented Sep 20, 2024

I added generated.go file as well.

And graphql server works well. I attached some logs from graphql server below.

{"body_size":116,"client_ip":"::1","error":"","file":"/Users/jeongsuyeon/IdeaProjects/suyeon-jung-dev/litmus/chaoscenter/graphql/server/api/middleware/logger.go:60","func":"main.setupGin.DefaultStructuredLogger.StructuredLogger.func2","latency":"16.802833ms","level":"info","method":"POST","msg":"","path":"/query","status":200,"time":"2024-09-20T21:00:03+09:00"}
{"body_size":90,"client_ip":"::1","error":"","file":"/Users/jeongsuyeon/IdeaProjects/suyeon-jung-dev/litmus/chaoscenter/graphql/server/api/middleware/logger.go:60","func":"main.setupGin.DefaultStructuredLogger.StructuredLogger.func2","latency":"16.807667ms","level":"info","method":"POST","msg":"","path":"/query","status":200,"time":"2024-09-20T21:00:03+09:00"}
{"file":"/Users/jeongsuyeon/IdeaProjects/suyeon-jung-dev/litmus/chaoscenter/graphql/server/graph/environment.resolvers.go:20","func":"github.com/litmuschaos/litmus/chaoscenter/graphql/server/graph.(*mutationResolver).CreateEnvironment","level":"info","msg":"request received to create new environment","projectId":"ef7f1c15-933c-4e2e-a44a-25d62da07649","time":"2024-09-20T21:00:27+09:00"}
{"body_size":259,"client_ip":"::1","error":"","file":"/Users/jeongsuyeon/IdeaProjects/suyeon-jung-dev/litmus/chaoscenter/graphql/server/api/middleware/logger.go:60","func":"main.setupGin.DefaultStructuredLogger.StructuredLogger.func2","latency":"27.907791ms","level":"info","method":"POST","msg":"","path":"/query","status":200,"time":"2024-09-20T21:00:27+09:00"}
{"file":"/Users/jeongsuyeon/IdeaProjects/suyeon-jung-dev/litmus/chaoscenter/graphql/server/graph/environment.resolvers.go:104","func":"github.com/litmuschaos/litmus/chaoscenter/graphql/server/graph.(*queryResolver).ListEnvironments","level":"info","msg":"request received to list environments","projectId":"ef7f1c15-933c-4e2e-a44a-25d62da07649","time":"2024-09-20T21:00:27+09:00"}
{"body_size":458,"client_ip":"::1","error":"","file":"/Users/jeongsuyeon/IdeaProjects/suyeon-jung-dev/litmus/chaoscenter/graphql/server/api/middleware/logger.go:60","func":"main.setupGin.DefaultStructuredLogger.StructuredLogger.func2","latency":"21.589334ms","level":"info","method":"POST","msg":"","path":"/query","status":200,"time":"2024-09-20T21:00:27+09:00"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

GraphQL validation fail with graphql-js
3 participants