ShopifySharp icon indicating copy to clipboard operation
ShopifySharp copied to clipboard

Explore a "fluent" builder for GraphQL queries/mutations

Open nozzlegear opened this issue 10 months ago • 1 comments

I'm very interested in adding a "fluent" query builder for GraphQL queries/mutations. Here's what I envision it looking like:

var builder = new GraphQueryBuilder();
var pageInfoFragment = new GraphQueryFragmentBuilder("pageInfoFragment", pageInfo =>
  pageInfo.StartCursor().EndCursor().HasNextPage().HasPreviousPage());

var query = builder.Query(query =>
  query.Products(p =>
    p.Arguments.First(10);
    p.PageInfo(pageInfo => pageInfo.Fragment(pageInfoFragment));
    p.Nodes(node =>
      node.Id();
      node.Title();
      node.VariantsCount(v => v.Count());
   )
  .Shop(s =>
    s.Id();
    s.Title();
    s.Plan(p => p.DisplayName());
  )
).Build();

var request = new 

One of the things I like about this is the potential for reusing parts of the code (such as the pageInfo fragment). This is just pseudo-code so there are a lot of actual implementation questions that are unanswered here, but I'd love to hear feedback about this before I start implementing it (and don't forget to check #1137 and #1072 as well).

nozzlegear avatar Jan 21 '25 04:01 nozzlegear

very good feature

ahinin79 avatar Feb 24 '25 05:02 ahinin79