我正在尝试执行以下操作,但它返回null:
import { Button as styledButton } from 'component-library'
Run Code Online (Sandbox Code Playgroud)
然后尝试将其渲染为:
import React, { PropTypes } from "react";
import cx from 'classNames';
import { Button as styledButton } from 'component-library';
export default class Button extends React.Component {
constructor(props){
super(props)
}
render() {
return (
<styledButton {...this.props}></styledButton>
)
}
}
Run Code Online (Sandbox Code Playgroud)
原因是,我需要Button从库中导入组件,并且还导出具有相同名称但保持导入组件功能的包装器组件.如果我import { Button } from component library当然离开它,我会得到一个多重声明错误.
有任何想法吗?
以前,我只是输入了input KeyInputas mode: String!,我希望将类型从 String 更改为!到自定义枚举。
我尝试过以下架构:
enum Mode= {
test
live
}
input KeyInput = {
mode: Mode!
}
type Key {
name,
mode
}
type Query {
Keys(input: KeyInput): [Key]
}
Run Code Online (Sandbox Code Playgroud)
我的查询如下所示:
query{
Keys(input: {mode: "test"}){
name
}
}
Run Code Online (Sandbox Code Playgroud)
但是,我收到以下错误:
"message": "Expected type Mode!, found \"test\"; Did you mean the enum value test?"
Run Code Online (Sandbox Code Playgroud)
是否可以让枚举值解析字符串值?如果我从输入中删除引号,它将起作用。但是,我需要能够继续将模式解析为字符串。
我有以下REST端点:
/ orders / {id}
returns {
orderId,
orderItem,
customerId
}
Run Code Online (Sandbox Code Playgroud)
/ customers / {id}
returns {
customerId,
firstName,
lastName
}
Run Code Online (Sandbox Code Playgroud)
我受到这两个端点的限制,这两个端点将包装在我的graphql模式中。
我想要以下架构:
type Order {
orderId: ID!,
orderItem: String,
customer: Customer
}
type Customer{
customerId: ID!
firstName: String!
lastName: String!
}
type Query {
getOrder(id: String!): Order,
getCustomer(id: String!): Customer
}
Run Code Online (Sandbox Code Playgroud)
我想知道是否可以让GraphQL解决Order类型的Customer对象?我了解您无法将查询结果传递给另一个参数。
我认为解析器getOrder是:
const getOrderResolver = axios.get(`/orders/${id}`)
.then((ordersRes) => {
let customerId;
if(ordersRes.data.customerId !== null) {
customerId = ordersRes.data.customerId
axios.get(`/customers/${customerId}`)
.then((customerRes) => ({
return {
orderId: ordersRes.data.orderId …Run Code Online (Sandbox Code Playgroud) 我似乎无法弄清楚为什么在执行提供数据主体的axios.post方法时,会在服务器上将其捕获为未定义。
我有以下带有代码片段的文件:
app.js:
auth(user, pass){
return axios.post('http://localhost:3000/auth', {
username: user,
password: pass
})
}
Run Code Online (Sandbox Code Playgroud)
server.js:
app.post('/auth', (req, res) => {
console.log(req.body) //undefined
res.end("Success")
})
Run Code Online (Sandbox Code Playgroud)
我该如何使用axios正确处理POST数据?我想念什么吗?
成功返回成功,但是在请求中的任何地方似乎都找不到用户名/密码
javascript ×4
ecmascript-6 ×2
graphql ×2
axios ×1
ecmascript-7 ×1
express ×1
graphql-js ×1
import ×1
reactjs ×1