Giter Club home page Giter Club logo

Comments (9)

byme8 avatar byme8 commented on August 30, 2024

If you want to generate a wrapper for your existing GraphQL queries that were written via GraphQL syntax use StrawberryShake

The ZeroQL allows you to write GraphQL queries with C# that's all. It doesn't generate queries from GraphQL files.

from zeroql.

En3Tho avatar En3Tho commented on August 30, 2024

I see. I just tried StrawberryShake and it just produces invalid 43mb file with almost 700k locs. This is utterly deranged.

I also tried @graphql-codegen/c-sharp npm package and as anything that comes from garbage script ecosystem it doesn't work either.

Your library is the only one that just works so I guess I'm sticking with it.

Can you give some pointers on how I can translate graphql query/mutation/fragments using your library? As far as I can see the transformation can be done, it's just that spec file needs to be parsed again so types can be checked.

I believe something like extension methods to a Query/Mutation types could be generated.

Also, as your library is already supporting fragments, I think it's possible to translate gql fragments definitions too.

from zeroql.

byme8 avatar byme8 commented on August 30, 2024

Your example:

query QueryName($queryParams) {
  actualQueryToCall($queryParams) {
    ...thingsToReturn
  }
}

It would look like that:

var client = new YourZeroQLClient(httpClient);
var queryParams = // some value
var response = await client.Query("QueryName", q => q.ActualQueryToCall(queryParams, o => o.ToThingsToReturn()))

// ...
public static class ThingsToReturnExtensions
{
   [GraphQLFragment]
    public static SomeReturnType ToThingsToReturn(this QueryType value)
    {
        return new SomeReturnType(value.Id, value.Name);
    }
}

The YourZeroQLClient is the client name specified during the generation. Basically, that's all.

from zeroql.

En3Tho avatar En3Tho commented on August 30, 2024

Thanks. I should have said automatically*. It's just there are so many of these queries that I'd rather tinker with your library and possibly do some pr if successful than write all that by hand.

from zeroql.

byme8 avatar byme8 commented on August 30, 2024

Oh, you meant automatically.

Potentially you could create a new CLI or extend the ZeroQL CLI tool that will parse existing graphql files with graphql parser and then generate calls for the "presumably existing" ZeroQL client.

In theory, it should not require any type information — just translation from raw GraphQL string to raw C# string. However, there are lots of places where something can go wrong.

from zeroql.

byme8 avatar byme8 commented on August 30, 2024

To encapsulate the query you can use GraphQL request syntax.

However, here comes another issue. You encapsulate the query and because of it can not return the anonymous type. As a result, you need to generate stub classes to map results to. The StrawberryShake does it.

from zeroql.

En3Tho avatar En3Tho commented on August 30, 2024

I see. Thank you for the insights.
One more question: how to send custom headers with the request? From the code I see, custom QueryPipeline should be created?

from zeroql.

byme8 avatar byme8 commented on August 30, 2024

how to send custom headers with the request? From the code I see, custom QueryPipeline should be created?

The client constructor requires the HTTP client. You can set any headers to this HTTP client at any moment, or you can implement IHttpHandler and pass it to the constructor to intercept and modify the HTTP call.

from zeroql.

byme8 avatar byme8 commented on August 30, 2024

Here you can find the example for IHttpHandler. It is a new feature and doesn't have documentation yet.

from zeroql.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.