剧场模式
首页前后端分离GraphQLGraphQL + React + React Router + Apollo 实战教程

GraphQL + React + React Router + Apollo 实战教程 #2 创建 graphql 服务器,定义 schema,开始实战(今天第四更)

海外散仙厉飞雨 · 真仙发布于
0

https://docs.spacexdata.com/?version=latest#cfcc49e7-5fe4-4dd3-9701-7c5caf7af9fb

https://github.com/hfpp2012/hello-GraphQL/blob/master/server/schema/schema.js

https://github.com/graphql/express-graphql

server.js

const express = require('express');

const graphqlHTTP = require('express-graphql');
const schema = require('./schema');

const app = express();

app.use('/graphql', graphqlHTTP({
  schema,
  graphiql: true
}));

app.listen(4000);

schema.js

const { GraphQLObjectType, GraphQLInt } = require('graphql');

const LaunchType = new GraphQLObjectType({
  name: "Launch",
  fields: () => ({
    flight_number: { type: GraphQLInt },
    mission_name: { type: GraphQLString },
    launch_year: { type: GraphQLString },
    launch_date_local: { type: GraphQLString },
    launch_success: { type: GraphQLBoolean },
    rocket: {type: RocketType },
  })
})

const RocketType = new GraphQLObjectType({
  name: "Rocket",
  fields: () => ({
    rocket_id: { type: GraphQLString },
    rocket_name: { type: GraphQLString },
    rocket_type: { type: GraphQLString }
  })
})
0 条回复
暂无回复~~

© 汕尾市求知科技有限公司 | 粤ICP备19038915号 | 在线学员:102

Top