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

How to set variable in mutation? #353

Closed
muslimmuda15 opened this issue Jul 1, 2024 · 4 comments
Closed

How to set variable in mutation? #353

muslimmuda15 opened this issue Jul 1, 2024 · 4 comments

Comments

@muslimmuda15
Copy link

muslimmuda15 commented Jul 1, 2024

I follow step by step the instruction until generate my graphql

dart run build_runner build

I tried to request my query from my widget

# port.graphql
query FindPortAndCity($options: ListOptions, $keyword: String, $zone_id: ID) {
  findPortAndCity(options: $options, keyword: $keyword, zone_id: $zone_id) {
    id
    type
    name
    location {
      latitude
      longitude
    }
    photos
  }
}

// port widget
Query_FindPortAndCity_Widget(
      options: Options_Query_FindPortAndCity(
        variables: Variables_Query_FindPortAndCity(
          keyword: searchText,
          zone_id: null,
          options: Input_ListOptions(
            active: null,
            limit: null,
            offset: null,
            order: Enum_SearchOrder.desc,
            orderBy: "created_at",
          ),
        ),
        fetchPolicy: FetchPolicy.networkOnly,
      ),
      builder: (result, {fetchMore, refetch}) {
      },
    );

everything working well.

But how to impelementation mutation?
I have graphql mutation

# create port
mutation CreateRfqTestMutation($data: InQuoteProjectLocation!) {
  createRfqTest(data: $data) {
    all_found {
      id
    }
    unmatch {
      id
    }
    match {
      id
    }
    pol_zone
  }
}

But I still confuse how to implement that?
Because it seem very diffeent with the query.

I implementation like this

useMutation_CreateRfqTestMutation(
    WidgetOptions_Mutation_CreateRfqTestMutation(
          variables: // i don't see variable here
    )
)

the useMutation required WidgetOptions_Mutation_CreateRfqTestMutation but, i cannot set variable inside there.

image

Please help me.

Copy link

github-actions bot commented Jul 1, 2024

👋 @muslimmuda15
Thank you for raising an issue. I will investigate the issue and get back to you as soon as possible.
Please make sure you have provided enough context.

This library is created and maintained by me, @budde377. Please consider supporting my work and ensure our survival by donating here.

@muslimmuda15 muslimmuda15 changed the title How to implementation mutation in Graphql Codegen? How to set variable in mutation? Jul 2, 2024
@budde377
Copy link
Contributor

budde377 commented Jul 3, 2024

Thanks for reaching out @muslimmuda15 - The useMutation* hook returns an object with a runMutation method on it. When you call this, you need to provide the variables.

@muslimmuda15
Copy link
Author

can you give me some example the full code, because i getting error like this, and i already using StatefulHookWidget
image

@budde377
Copy link
Contributor

budde377 commented Jul 9, 2024

Because the code-generator is just a wrapper around graphql and graphql_flutter, try and have a look at their documentation: https://github.com/zino-hofmann/graphql-flutter/tree/main/packages/graphql_flutter#mutations

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

No branches or pull requests

2 participants