如何在中继中进行身份验证
How to authenticate in relay
验证用户的正确点是什么?
以继电器入门套件为例。
这似乎是查询的重点(我已经添加了 args id)
var queryType = new GraphQLObjectType({
name: 'Query',
fields: () => ({
node: nodeField,
// Add your own root fields here
viewer: {
args: {
id: {
type: GraphQLString
},
},
type: userType,
resolve: (_, args) => getViewer(args.id),
},
}),
});
然后在数据库中做类似
的事情
getViewer: (id) => id === viewer.id ? viewer : null,
现在到了崩溃的地步,从哪里请求制作 ID?我会假设路线
export default class extends Relay.Route {
static queries = {
viewer: () => Relay.QL`
query {
viewer(id:"1")
}
`,
};
static routeName = 'AppHomeRoute';
}
这不起作用。
首先,您需要将一个身份验证中间件放入您的服务器 (http://passportjs.org/ for instance).Then you have to pass the auth information to the graphql middleware (read about how to do it here https://github.com/graphql/express-graphql#advanced-options) and you can finally access that information using the 3rd argument to the resolve(parentValue, args, -->session)
function. Here's what the actual auth endpoint could look like https://github.com/igorsvee/react-relay-example/blob/master/server/routes.js#L29-L51
验证用户的正确点是什么?
以继电器入门套件为例。
这似乎是查询的重点(我已经添加了 args id)
var queryType = new GraphQLObjectType({
name: 'Query',
fields: () => ({
node: nodeField,
// Add your own root fields here
viewer: {
args: {
id: {
type: GraphQLString
},
},
type: userType,
resolve: (_, args) => getViewer(args.id),
},
}),
});
然后在数据库中做类似
的事情getViewer: (id) => id === viewer.id ? viewer : null,
现在到了崩溃的地步,从哪里请求制作 ID?我会假设路线
export default class extends Relay.Route {
static queries = {
viewer: () => Relay.QL`
query {
viewer(id:"1")
}
`,
};
static routeName = 'AppHomeRoute';
}
这不起作用。
首先,您需要将一个身份验证中间件放入您的服务器 (http://passportjs.org/ for instance).Then you have to pass the auth information to the graphql middleware (read about how to do it here https://github.com/graphql/express-graphql#advanced-options) and you can finally access that information using the 3rd argument to the resolve(parentValue, args, -->session)
function. Here's what the actual auth endpoint could look like https://github.com/igorsvee/react-relay-example/blob/master/server/routes.js#L29-L51