我正在开发一个非常重要的应用程序,我们正在考虑使用GraphQL.在处理模式的初始草案时,我变得有点瘫痪,试图建立随着产品的成熟而扩展的命名约定.我真的很感激任何不得不发展架构并遇到或成功避免死角或不一致的人的一些见解:
在接口名称中保留名称"Interface"通常是有用/惯用的吗?例如,在大型应用程序中是优选Profile
还是ProfileInterface
优先?
interface ProfileInterface {
# fields here...
}
type UserProfile implements ProfileInterface {
# implemented fields here...
}
Run Code Online (Sandbox Code Playgroud)将单枚举值指定为"常量"是否常见?
enum GeoJSONFeatureTypeConstant {
feature
}
interface GeoJSONFeatureInterface {
id: ID
type: GeoJSONFeatureTypeConstant!
geometry: GeoJSONGeometryInterface!
properties: GeoJSONProperties
}
Run Code Online (Sandbox Code Playgroud)最好的做法是将全有或全无object
s 声明为scalar
或者type
,两者之间的界线在哪里?想象一下Point
通常表示为数组的类型[x,y]
; 哪个更像是风骚?
scalar Point
type Point {
x: Float
y: Float
}
Run Code Online (Sandbox Code Playgroud)提前致谢!
这个问题没有得到我想要的动力,所以我会在发现它们时开始发布有用的片段,这可能会演变成各种各样的答案.
在末尾使用Input命名输入类型是一种有用的约定,因为对于单个概念对象,您通常需要输入类型和输出类型略有不同.
我正在尝试启动我的 nestJs 服务器,它一直给我这个错误:
UnhandledPromiseRejectionWarning:错误:您必须await server.start()
在调用server.applyMiddleware()
ApolloServer之前
我什至不确定从哪里调试,因为我对 NestJs 和 GraphQL 还是很陌生。
我使用Express-graphql中间件.我在正文行中发送以下请求:
POST /graphql HTTP/1.1
Host: local:8083
Content-Type: application/graphql
Cache-Control: no-cache
Postman-Token: d71a7ea9-5502-d5fe-2e36-0ae49c635a29
{
testing {
pass(id: 1) {
idn
}
}
}
Run Code Online (Sandbox Code Playgroud)
并有错误
{
"errors": [
{
"message": "Must provide query string."
}
]
}
Run Code Online (Sandbox Code Playgroud)
在graphql中,我可以在URL中发送更新.
URL字符串太短.我必须发送更新模型
mutation {
update(id: 2, x1: "zazaza", x2: "zazaza", x3: "zazaza" ...(more more fields)...) {
idn
}
}
Run Code Online (Sandbox Code Playgroud)
我认为它必须在请求机构.我如何发送'更新'查询或我做错了?
在一个react本机项目中,我正在创建一个对象,然后将屏幕重定向到新创建的对象的详细信息页面,我收到此错误:
可能未处理的Promise拒绝(id:0):网络错误:存储错误:应用程序尝试编写没有提供id的对象,但商店已包含此对象的id为XYZ.
查看数据库,我看到在上一步中正确创建了该项.通过列表导航到同一屏幕和项目(不是在创建和重定向之后)似乎工作正常.我是否必须等待或以某种方式设置某种时间让阿波罗商店保持正确?
我正在使用标准的apollo客户端@graphql绑定/包装
GQL:
query getEvent($eventId: ID!) {
Event(id:$eventId) {
id
headline
photo
location
startTime
creator {
username
photo
}
}
}
`;
Run Code Online (Sandbox Code Playgroud)
这是一段代码片段
@graphql(getEventGql,{
options: ({route}) => {
console.log('route params', route.params);
return {
variables: {
eventId: route.params.eventId,
}
}
},
})
@connect((state) => ({ user: state.user }))
export default class EventDetailScreen extends Component {
...
Run Code Online (Sandbox Code Playgroud) 我目前正在尝试使用NodeJS的GraphQL,我不知道,为什么以下查询会出现此错误:
{
library{
name,
user {
name
email
}
}
}
Run Code Online (Sandbox Code Playgroud)
我不知道如果type
我的resolveLibrary
是正确的,因为在任何例子,我看了一下他们使用new GraphQL.GraphQLList()
,但对我来说我真想回到一个用户对象,而不是用户的数组.
我的代码:
const GraphQL = require('graphql');
const DB = require('../database/db');
const user = require('./user').type;
const library = new GraphQL.GraphQLObjectType({
name: 'library',
description: `This represents a user's library`,
fields: () => {
return {
name: {
type: GraphQL.GraphQLString,
resolve(library) {
return library.name;
}
},
user: {
type: user,
resolve(library) {
console.log(library.user);
return library.user
}
}
}
}
});
const resolveLibrary = {
type: …
Run Code Online (Sandbox Code Playgroud) GitHub的GraphQL API是否与内容API等效?
我似乎无法想出一个接受repo所有者,repo名称和文件路径的查询并返回该文件的内容.我猜它与树对象有关?
在GraphQL身份验证教程中,login
是一个Mutation:
type Mutation {
post(url: String!, description: String!): Link!
signup(email: String!, password: String!, name: String!): AuthPayload
login(email: String!, password: String!): AuthPayload
}
Run Code Online (Sandbox Code Playgroud)
登录不应该是查询,因为:
我在这里错过了什么吗?
我正在学习,GraphQL
所以我建了一个小项目.假设我有2个型号,User
并且Comment
.
const Comment = Model.define('Comment', {
content: {
type: DataType.TEXT,
allowNull: false,
validate: {
notEmpty: true,
},
},
});
const User = Model.define('User', {
name: {
type: DataType.STRING,
allowNull: false,
validate: {
notEmpty: true,
},
},
phone: DataType.STRING,
picture: DataType.STRING,
});
Run Code Online (Sandbox Code Playgroud)
关系是1:很多,用户可以有很多评论.
我已经构建了这样的架构:
const UserType = new GraphQLObjectType({
name: 'User',
fields: () => ({
id: {
type: GraphQLString
},
name: {
type: GraphQLString
},
phone: {
type: GraphQLString
},
comments: {
type: new GraphQLList(CommentType), …
Run Code Online (Sandbox Code Playgroud) 在我发现的模式文件中,我注意到某些类型后面有感叹号,例如
# Information on an account relationship
type AccountEdge {
cursor: String!
node: Account!
}
Run Code Online (Sandbox Code Playgroud)
这些是什么意思?我在文档中或通过谷歌搜索找不到任何相关内容
graphql ×10
graphql-js ×2
node.js ×2
apollo ×1
express ×1
github ×1
github-api ×1
idioms ×1
nestjs ×1
react-apollo ×1
reactjs ×1
relayjs ×1
schema ×1
sequelize.js ×1
server ×1
sql ×1