Giter Club home page Giter Club logo

graphql_api's Introduction

Apollo

Apollo allows you to execute queries and mutations against a GraphQL server, and returns results as query-specific Swift types. This means you don’t have to deal with parsing JSON, or passing around dictionaries and making clients cast values to the right type manually. You also don’t have to write model types yourself, because these are generated from the GraphQL definitions your UI uses

Raywenderlich 有篇 Nikolas Burk 的文章Getting started with GraphQL & Apollo on iOS可以帮助我们理解上面这段关于 Apollo 的描述.

在 Xcode 的 Build Phases 中添加这样一段脚本

$APOLLO_FRAMEWORK_PATH/check-and-run-apollo-codegen.sh generate $(find . -name '*.graphql') 
--schema schema.json --output API.swift

大意是: 找到 '*.graphql' 文件 并生成 API.swift.

脚本中的 schema.json 需要 Graphcool 提供的 __SIMPLE_API_ENDPOINT__ 才能获得.

apollo-codegen download-schema __SIMPLE_API_ENDPOINT__ --output schema.json

Prisma

这里要说的 Prisma 不是一款软件.


Prisma is a performant open-source GraphQL ORM-like layer doing the heavy lifting in your GraphQL server.

你可以把 Prisma 想成是一款最强劲的汽车引擎, 而 Graphcool 是一台刚出厂的华丽跑车 --- Nikolas Burk


  1. 开发流程

生成的 prisma.yml 文件可以做如下配置:

datamodel:数据库模型
endpoint: Prisma API的HTTP端点
secret:   JWT
schema:   Prism API的GraphQL schema的路径
subscriptions:订阅webhooks的配置
seed:   指向包含突变的种子数据文件
custom: 用于提供可在prisma.yml其他地方引用的变量

可以在 subscriptions 里 hook prisma deploy , 并 get-schema .

graphql get-schema --endpoint http://localhost:4466 --output prisma.graphql --no-all

graphql-yoga 设置 server 的 db 参数时会用到它 prisma-binding .

const { Prisma } = require('prisma-binding')

const prisma = new Prisma({
  typeDefs: 'prisma.graphql',
  endpoint: 'http://localhost:4466'
})

  1. 部署 Heroku

// 选择 TypeScript
graphql create heroku-demo

prisma.yml :

// 改用刚创建的 heroku server
endpoint: https://heroku-test11.herokuapp.com/heroku-demo/dev

index.ts :

db: new Prisma({
  // 同理
  endpoint: 'https://heroku-test11.herokuapp.com/heroku-demo/dev', 
  debug: true, 
})
//部署 service
prisma deploy
yarn start

"scripts": {
    "postinstall": "tsc",
    "start": "ts-node src/index.ts",
    ... ...
  },

Procfile :

web: node dist/index.js
heroku create 
git push heroku master
git remote set-url --add --push heroku https://github.com/paprikaLang/GraphQL-O.git
git remote set-url --add --push heroku https://git.heroku.com/secuxxxxxxxxxxxx731.git

git remote -v :

heroku	https://git.heroku.com/secuxxxxxxxxxx731.git (fetch)
heroku	https://github.com/paprikaLang/GraphQL-O.git (push)
heroku	https://git.heroku.com/secuxxxxxxxxxx731.git (push)

这样, GitHub 和 Heroku 可以同步上传代码了.


Gatsby

Contentful 部署 GraphQL 所需的 database:

Gatsby new 创建好项目并添加 Contentful 配置项:

{
  resolve:'gatsby-source-contentful',
  options: {
    spaceId:'SPACE_ID',
    accessToken:'ACCESS_TOKEN'
  }
}

gatsby develop 会加载配置好的 Contentful data.

import { StaticQuery, graphql } from 'gatsby'
const Layout = ({ children }) => (
  <StaticQuery
    query={graphql`
      query SiteTitleQuery {
      	...
        allContentfulLink(sort: {fields: [createdAt],order: ASC}){
          edges{
            node{
              title
              url
              createdAt }}}}
    `}
    render={data => ()} /> )

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.