• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

notrab/fakerql: Hosted faker GraphQL endpoint for frontend developers

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

notrab/fakerql

开源软件地址(OpenSource Url):

https://github.com/notrab/fakerql

开源编程语言(OpenSource Language):

TypeScript 100.0%

开源软件介绍(OpenSource Introduction):

FakerQL

FakerQL was created for frontend developers and GraphQL powered apps. Whether you're getting started with a new project or learning Relay/Apollo, you can forget about building a custom server and rely on Faker.js to provide some goodies!

Give it a try

You can head over to GraphiQL to send some example queries and mutations.

Queries

Get authorised user

You can request the logged in user provided you pass a valid Authorization header with a signed JWT. This can be done using the register/login mutations.

# me

{
  me {
    id
    firstName
    lastName
    email
    avatar
  }
}

Get a list of users

You can request a list of users. count is optional and defaults to 25.

# allUsers(count: Int)

{
  allUsers(count: 5) {
    id
    firstName
    lastName
    email
    avatar
  }
}

Get a User

You can request a single User by providing any ID.

# User(id: String!)

{
  allUsers(id: "wk0z1j1tzj7xc0116is3ckdrx") {
    id
    firstName
    lastName
    email
    avatar
  }
}

Get a list of products

You can request a list of products. count is optional and defaults to 25.

# allProducts(count: Int)

{
  allProducts(count: 5) {
    id
    name
    price
  }
}

Get a Product

You can request a single Product by providing any ID.

# Product(id: String!)

{
  allProduct(id: "cjbrygtdz3e480147hv8ozt40") {
    id
    name
    price
  }
}

Get a list of todos

You can request a list of todos. count is optional and defaults to 25.

# allTodos(count: Int)

{
  allTodos(count: 5) {
    id
    title
    completed
  }
}

Get a Todo

You can request a single Todo by providing any ID.

# Todo(id: String!)

{
  Todo(id: "cjbrygq0u3e4301476mfqoaae") {
    id
    title
    completed
  }
}

Get a list of posts

You can request a list of posts. count is optional and defaults to 25.

# allPosts(count: Int)

{
  allPosts(count: 5) {
    id
    title
    body
    published
    createdAt
    author {
      id
      firstName
      lastName
      avatar
    }
  }
}

Get a Post

You can request a single Post by providing any ID.

# Post(id: String!)

{
  Post(id: "cjbryfb1x3e3c0147f4f4110o") {
    id
    title
    body
    published
    createdAt
    author {
      id
      firstName
      lastName
      avatar
    }
  }
}

Mutations

Register user

Registering a User returns a random signed JWT. expiresIn is optional and pretty much pointless right now.

# register(email: String!, password: String!, expiresIn: String)

mutation {
  register(email: "[email protected]", password: "F4K3rqL!", expiresIn: '24h') {
    token
  }
}

Login user

Logging in a User returns a random signed JWT. expiresIn is optional and pretty much pointless right now.

# login(email: String!, password: String!, expiresIn: String)

mutation {
  login(email: "[email protected]", password: "F4K3rqL!") {
    token
  }
}

Updating user

This mutation returns the updated data you passed in to update.

# updateUser(id: ID!, email: String!, firstName: String, lastName: String)

mutation {
  updateUser(id: "wk0z1j1tzj7xc0116is3ckdrx", firstName: "Jim") {
    id
    firstName
    lastName
  }
}

➡️ You must specify the header Authorization: Bearer token to satisfy this mutation.

Create Todo

This mutation returns the data you sent arguments + a fake ID.

# createTodo(title: String!, completed: Boolean)

mutation {
  createTodo(title: "Book movie tickets") {
    id
    title
    completed
  }
}

Subscriptions

Coming soon.

Client side library example

The example below uses graphql-request.

import { request } from 'graphql-request';

const query = `{
  products: allProducts(count: 25) {
    id
    name
    price
  }

  user: User(id: "wk0z1j1tzj7xc0116is3ckdrx") {
    id
    firstName
    lastName
    email
    avatar
  }
}`;

request('https://fakerql.com/graphql', query).then(data => console.log(data));

Todo

  • Subscriptions
  • Custom directives



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap