Husqvik / GraphQlClientGenerator

GraphQL C# client generator
MIT License
213 stars 49 forks source link

Empty mutation request when using queryBuilder without values #114

Closed exedary closed 1 year ago

exedary commented 1 year ago

When building mutation, and there is no any values to retrun specified mutation is empty. Example:

var request = new MutationQueryBuilder()
            .WithCreateJob(
                new JobQueryBuilder(),
                input)
            .Build();

Returns "mutation{{}}"

Husqvik commented 1 year ago

Could you provide the GraphQL metadata and how the mutation should look like?

query IntrospectionQuery {
    __schema {
      queryType { name }
      mutationType { name }
      subscriptionType { name }
      types {
        ...FullType
      }
      directives {
        name
        description
        locations
        args {
          ...InputValue
        }
      }
    }
  }

  fragment FullType on __Type {
    kind
    name
    description
    fields(includeDeprecated: true) {
      name
      description
      args {
        ...InputValue
      }
      type {
        ...TypeRef
      }
      isDeprecated
      deprecationReason
    }
    inputFields {
      ...InputValue
    }
    interfaces {
      ...TypeRef
    }
    enumValues(includeDeprecated: true) {
      name
      description
      isDeprecated
      deprecationReason
    }
    possibleTypes {
      ...TypeRef
    }
  }

  fragment InputValue on __InputValue {
    name
    description
    type { ...TypeRef }
    defaultValue
  }

  fragment TypeRef on __Type {
    kind
    name
    ofType {
      kind
      name
      ofType {
        kind
        name
        ofType {
          kind
          name
            ofType {
            kind
            name
            ofType {
              kind
              name
              ofType {
                kind
                name
              }
            }
          }
        }
      }
    }
  }
exedary commented 1 year ago

metadata.txt

exedary commented 1 year ago

sry, github does not allow to upload in json format

exedary commented 1 year ago

Any updates?

Husqvik commented 1 year ago

There are two issues with your query

var request =
        new MutationQueryBuilder()
            .WithCreateJob(
                new JobQueryBuilder().WithAllScalarFields(), // you are missing to query at least one field from WithCreateJob mutation, GraphQL doesn't support void mutations
                input /* this is GraphQL parameter reference, OK */)
            .WithParameter(input) // missing - this is GraphQL parameter definition
            .Build()
exedary commented 1 year ago

Thank you! By the way it works with

var request = new MutationQueryBuilder()
            .WithCreateJob(
                new JobQueryBuilder().WithId(),
                input)
            .Build();

I mean without .WithParameter()

Husqvik commented 1 year ago

Probably depends on the server implementation but it's not valid query without the parameter definition. You should get something like Variable "$parameterName" is not defined.