GraphQlClientGenerator icon indicating copy to clipboard operation
GraphQlClientGenerator copied to clipboard

Error CS0122: QueryBuilderParameter<StringOperationFilterInput>.QueryBuilderParameter(string, string, StringOperationFilterInput is inaccessible due to its protection level

Open arjandouwes opened this issue 3 years ago • 1 comments

Used NuGet Packages:

  • GraphQlClientGenerator version 0.9.9
  • GraphQl.Client version 5.0.2
  • GraphQL.Client.Serializer.Newtonsoft version 5.0.2

Used Language: C# 10 .NET 6 (VS 2022 professional version 17.2.6)

I am trying to create the following query using the generated classes from GraphQlClientGenerator:

{ swReleases(where: {swreleaseCode:{ contains : "216"}}) 
 {
    swreleaseDescription
    swreleaseCode
 }
}

The query is being constructed as follows:

 SwreleaseFilterInput swreleaseFilterInput = new()
 {
      Swreleasecode= new(
                    "swreleaseCode",
                    GraphQlTypes.Swrelease,
                    new StringOperationFilterInput()
                    {
                        Contains = new QueryBuilderParameter<string?>(
                                        "swreleaseCode",
                                        GraphQlTypes.Swrelease,
                                        "216")
                    })
            };

   QueryBuilderParameter<SwreleaseFilterInput?> queryBuilderParameter = new(
                                                                     "swreleaseCode",
                                                                      GraphQlTypes.Swrelease,
                                                                      new QueryBuilderParameter<SwreleaseFilterInput> (
                                                                           "swreleaseFilterInput ", 
                                                                           nameof(swreleaseFilterInput), 
                                                                           swreleaseFilterInput));

SwreleaseQueryBuilder swreleaseQueryBuilder = new SwreleaseQueryBuilder().WithAllScalarFields();

QueryQueryBuilder queryQueryBuilder = new QueryQueryBuilder()
                                                    .WithSwReleases(swreleaseQueryBuilder, where: queryBuilderParameter);
var queryString = queryQueryBuilder.Build(Formatting.Indented);
GraphQL.GraphQLRequest swreleaseQuery = new()
{
    Query = queryString,
};
// call to the GraphQL endpoint and response processing code follows

The problem is that

new QueryBuilderParameter<string?>(...) 

produces Error CS0122: QueryBuilderParameter<string?>.QueryBuilderParameter(string, string, StringOperationFilterInput is inaccessible due to its protection level. When checking the generated base class, I found:

public class QueryBuilderParameter<T> : QueryBuilderParameter
{
...
 protected QueryBuilderParameter(string name, string graphQlTypeName, T value) : base(name, graphQlTypeName, value)
}

I have 2 questions:

  1. What is the correct way for constructing the above query using the generated classes?
  2. Should the constructor QueryBuilderParameter(string name, string graphQlTypeName, T value): base(name, graphQlTypeName, value) be decorated with the access modifier protected?

arjandouwes avatar Jul 20 '22 12:07 arjandouwes

could you provide the API metadata JSON? So I have the exact code available. Or just URL to the API if it's public.

you can retrieve the metadata by querying

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
              }
            }
          }
        }
      }
    }
  }

Husqvik avatar Jul 20 '22 13:07 Husqvik