Mock your future API or extend the existing API with realistic data from faker.js. No coding required.All you need is to write GraphQL SDL. Don't worry, we will provide you with examples in our SDL editor.
In the GIF below we add fields to types inside real GitHub API and you can make queries from GraphiQL, Apollo, Relay, etc. and receive real data mixed with mock data.
We use @fake
directive to let you specify how to fake data. And if 60+ fakers is not enough for you, just use @examples
directive to provide examples. Use @listLength
directive to specify number of returned array items. Add a directive to any field or custom scalar definition:
type Person {
name: String @fake(type: firstName)
gender: String @examples(values: ["male", "female"])
pets: [Pet] @listLength(min: 1, max: 10)
}
No need to remember or read any docs. Autocompletion is included!
streetAddress
, firstName
, lastName
, imageUrl
, lorem
, semver
npm install -g graphql-faker
or run it in a Docker container, see Usage with Docker
Mock GraphQL API based on example SDL and open interactive editor:
graphql-faker --open
Note: You can specify non-existing SDL file names - Faker will use example SDL which you can edit in interactive editor.
Extend real data from SWAPI with faked data based on extension SDL:
graphql-faker ./ext-swapi.graphql --extend http://swapi.apis.guru
Extend real data from GitHub API with faked data based on extension SDL (you can get token here):
graphql-faker ./ext-gh.graphql --extend https://api.github.com/graphql \
--header "Authorization: bearer <TOKEN>"
graphql-faker [options] [SDL file]
[SDL file]
- path to file with SDL. If this argument is omitted Faker uses default file name.
-p
, --port
HTTP Port [default: env.PORT
or 9002
]-e
, --extend
URL to existing GraphQL server to extend-o
, --open
Open page with SDL editor and GraphiQL in browser-H
, --header
Specify headers to the proxied server in cURL format, e.g.: Authorization: bearer XXXXXXXXX
--forward-headers
Specify which headers should be forwarded to the proxied server--co
, --cors-origin
CORS: Specify the custom origin for the Access-Control-Allow-Origin header, by default it is the same as Origin
header from the request-h
, --help
Show helpWhen specifying the [SDL file]
after the --forward-headers
option you need to prefix it with --
to clarify it's not another header. For example:
graphql-faker --extend http://example.com/graphql --forward-headers Authorization -- ./temp.faker.graphql
When you finish with an other option there is no need for the --
:
graphql-faker --forward-headers Authorization --extend http://example.com/graphql ./temp.faker.graphql
docker run -p=9002:9002 apisguru/graphql-faker [options] [SDL file]
To specify a custom file, mount a volume where the file is located to /workdir
:
docker run -v=${PWD}:/workdir apisguru/graphql-faker path/to/schema.sdl
Because the process is running inside of the container, --open
does not work.
npm i
npm run build:all
npm run start
大数据如何模拟数据 我们如何在Stripe推动React组件测试和示例 (How we power React component tests and examples at Stripe) GraphQL’s main benefit for frontend developers has always been excellent tooling and developer experienc
团队18年初开始调研并实践 GraphQL,但是我在忙于旧项目的开发,短期并没有参与到新项目中,因此实际开始接触 GraphQL,是在18年中旬。 18年初的新项目由于工期比较紧张,虽然说尝试了下 GraphQL,但是其实并没有多少积累,前端只是简单地拼接查询字符串后发请求,后端也只是简单的解析了一下查询字符串,并没有将整个 GraphQL 生态中相关的工具给利用起来。 18年中旬开始接手一个使用
1.graphql的基本概念 GraphQL 是一种针对 Graph(图状数据)进行查询特别有优势的 Query Language(查询语言),所以叫做 GraphQL。 它跟 SQL 的关系是共用 QL 后缀,就好像「汉语」和「英语」共用后缀一样,但他们本质上是不同的语言。 GraphQL 并没有和任何特定数据库或者存储引擎绑定,而是依靠你现有的代码和数据支撑。 向你的 API 发出一个 Gra
GraphQL是API的查询语言,不依赖任何前端后台技术。在服务器端有很多种实现。 本例使用的是graphql-ruby(rails) ,用来解析传入的查询,并进行数据库调用,响应返回JSON,替换rails的api。 首先了解下graphql的几个组成部分 Queries:从API获取特定的数据。将查询设置为只读,就像Rest里面的Get,但是查询不仅是Get。 Mutations: 突变,
快速开始 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