Laravel框架中集成GraphQL
Laravel  /  管理员 发布于 2个月前   96
依赖包
1.nuwave/lighthouse
Lighthouse是Laravel应用程序的模式优先GraphQL包。
2.mll-lab/laravel-graphql-playground
在线调试工具,用于测试和浏览模式的UI
3.mll-lab/graphql-php-scalars
引入自定义php标量,用于https://github.com/webonyx/graphql-php的自定义标量类型的集合
安装集成步骤
1.安装nuwave/lighthouse
composer require nuwave/lighthouse
2. 安装在线调试工具 mll-lab/laravel-graphql-playground
composer require mll-lab/laravel-graphql-playground
3. 发布默认模式与相关配置
php artisan vendor:publish --provider="Nuwave\Lighthouse\LighthouseServiceProvider"
会在相应目录中生成相关文件:
config/lighthouse.php
graphql/schema.graphql
4. 引入自定义 php 标量 mll-lab/graphql-php-scalars
composer require mll-lab/graphql-php-scalars
5. 更新 graphql/schema.graphql文件
1). 创建 graphql/traits 目录
2). 更新 graphql/schema.graphql文件
"A datetime string with format `Y-m-d H:i:s`, e.g. `2018-01-01 13:00:00`."
scalar DateTime @scalar(class: "Nuwave\\Lighthouse\\Schema\\Types\\Scalars\\DateTime")
"A date string with format `Y-m-d`, e.g. `2011-05-23`."
scalar Date @scalar(class: "Nuwave\\Lighthouse\\Schema\\Types\\Scalars\\Date")
"A datetime string with format `Y-m-d H:i:s`, e.g. `2018-05-23 13:43:32`."
scalar DateTime @scalar(class: "Nuwave\\Lighthouse\\Schema\\Types\\Scalars\\DateTime")
scalar Email @scalar(class: "MLL\\GraphQLScalars\\Email")
scalar JSON @scalar(class: "MLL\\GraphQLScalars\\JSON")
scalar Mixed @scalar(class: "MLL\\GraphQLScalars\\Mixed")
type Query
type Mutation
#import traits/*.graphql
3). 创建 traits/users.graphql文件
extend type Query {
users: [User!]! @paginate(defaultCount: 10)
user(id: ID @eq): User @find
}
type User {
id: ID!
name: String!
email: String!
created_at: DateTime!
updated_at: DateTime!
}
更多使用 请访问官方手册:
https://lighthouse-php.com/
nkt 在
阿里云香港服务器搭建自用vpn:Shadowsocks使用流程步骤中评论 用了三分钟就被禁了,直接阿里云服务器22端口都禁了..熊丽 在
安装docker + locust + boomer压测环境实现对接口的压测中评论 试试水..博主 在
阿里云香港服务器搭建自用vpn:Shadowsocks使用流程步骤中评论 @test 也可能是国内大环境所至,也是好事,督促你该研究学习新技术..test 在
阿里云香港服务器搭建自用vpn:Shadowsocks使用流程步骤中评论 打了一次网页,然后再也打不开了。。是阿里云的缘故吗?..博主 在
centos7中Meili Search搜索引擎安装流程步骤中评论 @鹿 执行以下命令看看你的2.27版本是否存在strin..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号