All Projects → sahb1239 → SAHB.GraphQLClient

sahb1239 / SAHB.GraphQLClient

Licence: MIT license
Query HTTP api using GraphQL. The client recieves a model as typeparameter and then queries the GraphQL api and deserilize the result.

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to SAHB.GraphQLClient

galoy-pay
A web application that can be used to send tips or payments to users
Stars: ✭ 21 (-44.74%)
Mutual labels:  graphql-client
kobby
Kobby is a codegen plugin of Kotlin DSL Client by GraphQL schema. The generated DSL supports execution of complex GraphQL queries, mutation and subscriptions in Kotlin with syntax similar to native GraphQL syntax.
Stars: ✭ 52 (+36.84%)
Mutual labels:  graphql-client
graphql-typed-client
Strongly typed GraphQL client for .NET
Stars: ✭ 16 (-57.89%)
Mutual labels:  graphql-client
character-overlay
Web App for adding an OBS overlay with character information such as name, picture, and health for your favorite role-playing game.
Stars: ✭ 17 (-55.26%)
Mutual labels:  graphql-client
nim-graphql
Nim implementation of GraphQL with sugar and steroids
Stars: ✭ 47 (+23.68%)
Mutual labels:  graphql-client
LiveGQL
Use GraphQL Subscriptions on iOS 👌
Stars: ✭ 84 (+121.05%)
Mutual labels:  graphql-client
StarWars
Minimal GraphQL based Jetpack Compose, Wear Compose and SwiftUI Kotlin Multiplatform sample (using StarWars endpoint - https://graphql.org/swapi-graphql)
Stars: ✭ 165 (+334.21%)
Mutual labels:  graphql-client
graphql-demo
graphql前端实践
Stars: ✭ 21 (-44.74%)
Mutual labels:  graphql-client
python-graphql-client
Simple module for making requests to a graphQL server in python.
Stars: ✭ 65 (+71.05%)
Mutual labels:  graphql-client
elm-graphql
GraphQL made easy in Elm!
Stars: ✭ 56 (+47.37%)
Mutual labels:  graphql-client
showcase
A Full Stack Journey with Micro Services and Micro Front Ends. Using dapr, kubernetes, react module federation and web assembly,
Stars: ✭ 45 (+18.42%)
Mutual labels:  graphql-client
PropMapper
Object mapper for .NET. Flat and basic, but FAST.
Stars: ✭ 30 (-21.05%)
Mutual labels:  object-mapper
neo4j-graphql-java
Pure JVM translation for GraphQL queries and mutations to Neo4j's Cypher
Stars: ✭ 94 (+147.37%)
Mutual labels:  graphql-client
vue-gql
A small and fast GraphQL client for Vue.js
Stars: ✭ 32 (-15.79%)
Mutual labels:  graphql-client
Venflow
A brand new, fast and lightweight ORM, build for PostgreSQL.
Stars: ✭ 162 (+326.32%)
Mutual labels:  object-mapper
flutter-graphql
A GraphQL client for Flutter, bringing all the features from a modern GraphQL client to one easy to use package. Built after react apollo
Stars: ✭ 45 (+18.42%)
Mutual labels:  graphql-client
aws-mobile-appsync-sdk-android
Android SDK for AWS AppSync.
Stars: ✭ 101 (+165.79%)
Mutual labels:  graphql-client
ghql
GraphQL R client
Stars: ✭ 128 (+236.84%)
Mutual labels:  graphql-client
gql-query-builder
This is a GraphQL query builder.
Stars: ✭ 30 (-21.05%)
Mutual labels:  graphql-client
py-graphql-client
Dead-simple GraphQL client with subscriptions over websockets
Stars: ✭ 36 (-5.26%)
Mutual labels:  graphql-client

SAHB.GraphQL.Client

Query HTTP api using GraphQL. The client recieves a model as typeparameter and then queries the GraphQL api and deserilize the result.

Nuget

The library can be found on NuGet with the package name SAHB.GraphQL.Client. For pre release builds the NuGet package feed from AppVeyor can be used.

Older versions (1.1 and later) can be found on SAHB.GraphQLClient.

It can be installed using the following command in the Package Manager Console.

Install-Package SAHB.GraphQL.Client

The client supports the following frameworks:

SAHB.GraphQL.Client:

  • .NET Standard 1.2
  • .NET Framework 4.5.2

SAHB.GraphQL.Client.Subscription:

  • .NET Standard 2.0
  • .NET Framework 4.5.2

Documentation

Documentation can be found in this readme and in Documentation.md file.

Building

In order to build this project some additional steps is needed to generate a Version.props file. The easiest way is to execute the following commands:

git submodule update --init --recursive
cd Build
.\build.ps1 -Target "Build"

Another way is creating the file Version.props. The file should be at the root directory of the repository and contain the following:

<Project>
	<PropertyGroup>
		<Version>2.1.0-unstablebuild</Version>
	</PropertyGroup>
</Project>

Examples

An example for the Starwars API.

// TODO: Use dependency injection (services.AddGraphQLHttpClient()) (IServiceCollection)
// Initilize GraphQLClient
IGraphQLHttpClient client = GraphQLHttpClient.Default();

// Get response from url
var response = await client.Query<Query>("https://mpjk0plp9.lp.gql.zone/graphql");

// Get name etc.
Console.WriteLine(response.Hero.Name);

The example uses the following query classes:

public class Query
{
   public CharacterOrPerson Hero { get; set; }
}
        
public class CharacterOrPerson
{
   public string Name { get; set; }
   public IEnumerable<Friend> Friends { get; set; }
}

public class Friend
{
   public string Name { get; set; }
}

The following code requests the endpoint with the following query

{"query":"query{hero{name friends{name}}}"} 

The following using statements is required

using SAHB.GraphQLClient;
using SAHB.GraphQLClient.Extentions;

More examples can be found in Examples.md

Arguments

It's possible to add arguments to queries. This can be done with the attribute GraphQLArgumentAttribute. This attribute takes 3 arguments where the first is argument name used on the GraphQL server. The second is the argument type, for example String. The third argument is the varible name which should be used when the query is requested.

public class Query
{
   [GraphQLArgumentAttribute("argumentName", "ArgumentType", "variableName")]
   public Hero Hero { get; set; }
}

The client is requested as shown here:

var response = await client.Query<Query>("https://mpjk0plp9.lp.gql.zone/graphql", 
   arguments: new GraphQLQueryArgument("variableName", "valueToBeSent"});

This will generate the query (Hero contains here only the Name property):

{"query":"query{hero(argumentName:\"valueToBeSent\"){name}}"}

Renaming of a field

To rename a field name use the attribute GraphQLFieldNameAttribute on the class or property which you want to remap. For example request the field Fullname on the property Name do the follwing.

public class Friend
{
   [GraphQLFieldName("fullname")
   public string Name { get; set; }
}

This will generate the query:

{"query":"query{hero{Name:fullname"}

Note: For generating this you need to remember to add a extra Query class

public class Query
{
   public Hero Hero { get; set; }
}

Ignoring a field

To ignore a field use the attribute GraphQLFieldIgnoreAttribute on the class or property which you want to ignore. For example:

public class Hero
{
   public string Name { get; set; }

   [GraphQLFieldIgnore]
   public string IgnoredField { get; set; }
}

Example for ignoring a class

public class Hero
{
   public string Name { get; set; }

   public IgnoredClass IgnoredField { get; set; }
}

[GraphQLFieldIgnore]
public class IgnoredClass
{
   public string SomeProperty { get; set; }
}

This will generate the query:

{"query":"query{hero{name}}"}

Note: For generating this you need to remember to add a extra Query class

public class Query
{
   public Hero Hero { get; set; }
}

Subscriptions

The GraphQLclient has a subscription client which can be found here: SAHB.GraphQLClient.Subscription. Documentation can be found in Documentation.md file.

Introspection

The GraphQLclient has a package which contains a introspection query to inspect the GraphQL type system and a validator to validate C# queries against the introspection output. It can be found here: SAHB.GraphQLClient.Introspection. Documentation can be found in Documentation.md file.

Example projects

Example projects can be found in the path examples

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].