Skip to content

GraphQL fluent querybuilders that do not implement IGraphOperationQueryBuilder<T> require the Query text to be wrapped (6.27.0) #1246

Description

@lanthonyneville

I think this is a general rule with the querybuilders that implement IQuery but not IGraphOperationQueryBuilder ... at least it is with the ones I am using (ProductQueryBuilder & ProductVariantQueryBuilder):

After generating the query text with query.Build(), this cannot be applied as-is to the Query property of a GraphRequest. If you do you get an "unexpected identifier" error response from the API.

What you have to do is wrap the query text inside

query { ... query text ... }

as in the following code:

        public static T Execute<T>(this IQuery query, GraphService service)
        {
            var queryText = query.Build();
            var request = new GraphRequest()
            {
                Query = $"query {{ {queryText} }}",
                UserErrorHandling = ShopifySharp.Services.Graph.GraphRequestUserErrorHandling.Throw
            };
            var result = service.PostAsync<T>(request).Result.Data;
            return result;
        }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions