This is an implementation of Facebook's GraphQL in .NET.
Now the specification is being developed by theGraphQL Foundation.
This project uses a lexer/parser originally writtenby Marek Magdziak and released with a MIT license. Thank you Marek!
Provides the following packages:
Package | Downloads | NuGet Latest |
---|---|---|
GraphQL | ||
GraphQL.SystemTextJson | ||
GraphQL.NewtonsoftJson | ||
GraphQL.MemoryCache | ||
GraphQL.DataLoader | ||
GraphQL.SystemReactive | ||
GraphQL.MicrosoftDI |
You can get all preview versions from GitHub Packages.Note that GitHub requires authentication to consume the feed. See here.
master
branch.All packages generated from this repository come with embedded pdb and support Source Link.If you are having difficulty understanding how the code works or have encountered an error, then it is just enough to enableSource Link in your IDE settings. Then you can debug GraphQL.NET source code as if it were part of your project.
This is the main package, the heart of the repository in which you can find all the necessary classesfor GraphQL request processing.
> dotnet add package GraphQL
For serialized results, you'll need an IDocumentWriter
implementation.We provide several serializers (or you can bring your own).
> dotnet add package GraphQL.SystemTextJson
> dotnet add package GraphQL.NewtonsoftJson
Note: You can use
GraphQL.NewtonsoftJson
with .NET Core 3+, just be aware it lacks async writingcapabilities so writing to an ASP.NET Core 3.0HttpResponse.Body
will require you to setAllowSynchronousIO
totrue
as per this announcement;which isn't recommended.
For caching of parsed GraphQL documents you'll need an IDocumentCache
implementation.We provide in-memory implementation on top of Microsoft.Extensions.Caching.Memory
package.
> dotnet add package GraphQL.MemoryCache
For more information see Document Caching.
DataLoader is a generic utility to be used as part of your application's data fetching layerto provide a simplified and consistent API over various remote data sources such as databasesor web services via batching and caching.
> dotnet add package GraphQL.DataLoader
For more information see DataLoader.
Note: Prior to version 4, the contents of this package was part of the main GraphQL.NET package.
For handling subscriptions you'll need an instance of DocumentExecuter
that supports thisGraphQL operation type. DocumentExecuter
class from the main GraphQL.NET package supportsonly queries and mutations. We provide SubscriptionDocumentExecuter
implementation on topof System.Reactive
packages.
> dotnet add package GraphQL.SystemReactive
For more information see Subscriptions.
Also we provide some extra classes for advanced dependency injection usage on top ofMicrosoft.Extensions.DependencyInjection.Abstractions
package.
> dotnet add package GraphQL.MicrosoftDI
For more information see Thread safety with scoped services.
https://github.com/graphql-dotnet/examples
You can also try an example of GraphQL demo server inside this repo - GraphQL.Harness.It supports the popular IDEs for managing GraphQL requests and exploring GraphQL schema:
You can see the changes in public APIs using fuget.org.
Define your schema with a top level query object then execute that query.
Fully-featured examples can be found here.
var schema = Schema.For(@"
type Query {
hello: String
}
");
var root = new { Hello = "Hello World!" };
var json = await schema.ExecuteAsync(_ =>
{
_.Query = "{ hello }";
_.Root = root;
});
Console.WriteLine(json);
This example uses the GraphQL schema language.See the documentation formore examples and information.
public class Droid
{
public string Id { get; set; }
public string Name { get; set; }
}
public class Query
{
[GraphQLMetadata("droid")]
public Droid GetDroid()
{
return new Droid { Id = "123", Name = "R2-D2" };
}
}
var schema = Schema.For(@"
type Droid {
id: ID
name: String
}
type Query {
droid: Droid
}
", _ => {
_.Types.Include<Query>();
});
var json = await schema.ExecuteAsync(_ =>
{
_.Query = "{ droid { id name } }";
});
public class Droid
{
public string Id { get; set; }
public string Name { get; set; }
}
public class Query
{
private List<Droid> _droids = new List<Droid>
{
new Droid { Id = "123", Name = "R2-D2" }
};
[GraphQLMetadata("droid")]
public Droid GetDroid(string id)
{
return _droids.FirstOrDefault(x => x.Id == id);
}
}
var schema = Schema.For(@"
type Droid {
id: ID
name: String
}
type Query {
droid(id: ID): Droid
}
", _ => {
_.Types.Include<Query>();
});
var json = await schema.ExecuteAsync(_ =>
{
_.Query = $"{{ droid(id: \"123\") {{ id name }} }}";
});
The package publishing process is automated with GitHub Actions.
After your PR is merged into master
or develop
, preview packages are published to GitHub Packages.
Stable versions of packages are published to NuGet when a release is created.
This project exists thanks to all the people who contribute.
PRs are welcome! Looking for something to work on? The list of open issuesis a great place to start. You can help the project simply respond to some of the asked questions.
The default branch is master
. It is designed for non-breaking changes, that is to publish versions 4.x.x.If you have a PR with some breaking changes, then please target it to the develop
branch.
Thank you to all our backers!
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. Become a sponsor.
快速开始 GraphQL 是一种用于 API 的查询语言。这是 GraphQL 和 REST 之间一个很好的比较 (译者注: GraphQL 替代 REST 是必然趋势)。在这组文章中, 我们不会解释什幺是 GraphQL, 而是演示如何使用 @nestjs/GraphQL 模块。 GraphQLModule 只不过是 Apollo 服务器的包装器。我们没有造轮子, 而是提供一个现成的模块, 这让
GraphQL 既是一种用于 API 的查询语言也是一个满足你数据查询的运行时。 GraphQL 对你的 API 中的数据提供了一套易于理解的完整描述,使得客户端能够准确地获得它需要的数据,而且没有任何冗余,也让 API 更容易地随着时间推移而演进,还能用于构建强大的开发者工具。 向你的 API 发出一个 GraphQL 请求就能准确获得你想要的数据,不多不少。 GraphQL 查询总是返回可预测
Graphql editor 是一款 Graphql 的可视化编辑器和 IDE,帮助用户更容易理解 GraphQL 模式,通过使用可视化块系统创建模式。GraphQL Editor 将把它们转化为代码。通过 GraphQL Editor,用户可以在不写任何代码的情况下创建可视化的图表,或者以一种很好的方式呈现其模式。 GraphQL View Code Editor View Hierarchy View
GraphQL CLI Help us to improve new GraphQL CLI. Check out the new structure and commands below!Feel free to contact us in Discord channel. We would love to hear your feedback. Features Helpful command
Fullstack GraphQL Simple Demo Application API built with Node + Express + GraphQL + Sequelize (supports MySQL, Postgres, Sqlite and MSSQL). WebApp built with React + Redux. Written in ES6 using Babel
Hasura GraphQL Engine Hasura is an open source product that accelerates API development by 10x by giving you GraphQL or REST APIs with built in authorization on your data, instantly. Read more at hasu
这是利用Koa + GraphQL + Apollo-Server实现的,学生信息增、删、改、查的栗子 本栗子将搭配Koa实现一个GraphQL查询,逐步从简单Kao服务、到Mongodb的数据插入查询、再到GraphQL的使用,让大家快速看到: 搭建Koa搭建一个后台项目 后台路由简单处理方式 利用Mongoose简单操作Mongodb的增、删、改、查 掌握Apollo-Server简单操作数据
GraphQL Ruby 是 GraphQL 的一个 Ruby 实现。 Website API Documentation Newsletter 安装: # Gemfilegem 'graphql' $ bundle install 旨在: 实现 GraphQL 规范并支持一个 Relay 前端 在可能的情况下,提供与参考实现相似的习惯性的、简单的 Ruby API 支持 Ruby on Rails 和 Relay