Passing parameters as JSON to GraphQL API

View in #prefect-community on Slack

Nico_Neumann @Nico_Neumann: Hey!
I try to interact with the GraphQL api and I want to set the default parameters for a flow group. What is the right way to pass the parameters (as dict/json) into the query?
I have a query like this:

mutation {
  set_flow_group_default_parameters(
    input: {
      flow_group_id: "...", 
      parameters: {"name": "test"}
    } 
  ) {
    success
  }
}

But I get Syntax Error: Expected Name, found String "name".
When I remove the quotes from name the query runs but I get "Expected type JSON!, found {name: \"test\"}; 'ObjectValueNode' object has no attribute 'value'"
I found this test in prefect/server:

success = await api.flow_groups.set_flow_group_default_parameters(flow_group_id=flow_group_id, parameters={"meep": "morp", "bleep": "blorp"})

Kevin_Kho @Kevin_Kho: Looking into this
I find even with the warning it still works:
as a python script

query = """
mutation SetDefaultParams($input: set_flow_group_default_parameters_input!){
  set_flow_group_default_parameters(input: $input) {
    success
  }
}
"""

from prefect.client import Client 
client = Client()
_input = {"input": 
      {
        "flow_group_id": "7fb20810-cd37-41cf-9b04-218c284f6db5", 
        "parameters": {"x": "test test test"}
      }
} 

print(client.graphql(query, variables=_input))

Nico_Neumann @Nico_Neumann: @Kevin_Kho Thanks a lot, works great!

Adding a picture for Interactive API tab in the UI. This works despite the red squiggly

1 Like