Skip to content

dibble-james/LinQL

Repository files navigation

LinQL

LINQ-like access to GraphQL endpoints in .Net

Nuget

NuGet Badge

Supported Operations

  • Queries
  • Mutations
  • Input Types
  • Arguments
  • Interfaces/Unions
  • Auto-generating types via introspection
  • Subscriptions
  • Custom Scalars

Coming soon

  • Strawberry Shake support

Getting Started using GraphQL.Client

  1. Install the Nuget package
dotnet add package LinQL
dotnet add package LinQL.GraphQL.Client
  1. Reference a .graphql SDL in your csproj
<ItemGroup>
    <AdditionalFiles Include="StarWars.graphql" LinQLClientNamespace="StarWars.Types" />
</ItemGroup>
  1. Create a client:
using StarWars.Types;

var client = new GraphQLHttpClient(
    "https://swapi-graphql.netlify.app/.netlify/functions/index",
    new SystemTextJsonSerializer(new JsonSerializerOptions().WithKnownInterfaces()))
    .WithLinQL(new LinQLOptions().WithKnownScalars());
  1. Write queries!
using GraphQL.Client.Abstractions;
using StarWars.Types; // As defined by LinQLClientNamespace

public class StarWarsClient
{
    private readonly IGraphQLClient graph;

    public StarWarsClient(IGraphQLClient graph) => this.graph = graph;

    public async Task<Film> GetFilmById(string id, CancellationToken cancellationToken)
        => await this.graph.SendAsync((Root x) => x.GetFilm(id), cancellationToken);
}

Getting Started using StrawberryShake

Coming soon...

What can I do with it?

A range of expressions can be converted as demonstrated by the TranslationProviderTests. If you come accross something that doesn't work, please raise an issue or a pull request with a supporting test.

For more help check out the docs

Troubleshooting

There are a couple gotchas with the source generator that can be solved using the guides here