Skip to content

prints independent operation name #393

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

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

Conversation

vasilich6107
Copy link
Contributor

@vasilich6107 vasilich6107 commented May 21, 2025

Hi @budde377

this PR adds printing of an independent operation name for the cases when we do not use graphql and graphql_flutter clients.

For example when we use https://github.com/artflutter/graphql_flutter_bloc and want to pass operationName to WatchQueryOptions
https://github.com/artflutter/graphql_flutter_bloc/blob/master/test/query_bloc_test.dart#L26

I see that there is a class WatchOptions$Query but it is being generated only in case if we add client generation.

@vasilich6107
Copy link
Contributor Author

One more thing that we probably could try is...

@vasilich6107 vasilich6107 force-pushed the print-independent-operation-name branch from a0fb3e7 to 3c0cd0d Compare May 21, 2025 08:53
@vasilich6107 vasilich6107 force-pushed the print-independent-operation-name branch from 3c0cd0d to 4ab9e58 Compare May 21, 2025 08:54
@vasilich6107
Copy link
Contributor Author

This is it

Added an ability to access the operation name via static variable operationNameDefinition which is useful in tests for mocking purposes

smth like

if(oprationName == WatchQueryOptions.operationNameDefinition) {
  // then return some mock
}

@vasilich6107
Copy link
Contributor Author

If this approach makes sense for you I will finish the tests

@budde377
Copy link
Contributor

Thanks for suggesting this @vasilich6107! Some minor suggestions:

I think it would make sense to store the operation name next to the document node, e.g.

const documentNodeMutationX = ...
const operantionNameMutationX = ...

That way you will always generate the operation name regardless of the client being present.

You can still expose it as you suggest on the options.

I would be nice if we are consistent on exposing it across the options, also the watch-options.

A protip for getting the tests updated would be to

  1. Update the packages/graphql_codegen/test/builder_test.dart file to make the test override the files.
  2. Run tests.
  3. Review the new files.
  4. Change back the lines above.

@vasilich6107
Copy link
Contributor Author

Hi @budde377
Could you check the fixes

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.

2 participants