Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/422.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何更改graphql端点url名称_Javascript_Reactjs_Graphql_React Apollo - Fatal编程技术网

Javascript 如何更改graphql端点url名称

Javascript 如何更改graphql端点url名称,javascript,reactjs,graphql,react-apollo,Javascript,Reactjs,Graphql,React Apollo,我刚刚开始在apollo客户端上使用graphql,我已经安装了graphql服务器,正在运行localhost:4000,这是我的客户端 index.js const client = new ApolloClient({ uri: "http://localhost:4000/graphql", cache: new InMemoryCache() }); blog.js const GET_BLOG = gql` { post(id:"5ab2b46d9419

我刚刚开始在apollo客户端上使用graphql,我已经安装了graphql服务器,正在运行localhost:4000,这是我的客户端

index.js

const client = new ApolloClient({
    uri: "http://localhost:4000/graphql",
    cache: new InMemoryCache()
});
blog.js

const GET_BLOG = gql`
  {
    post(id:"5ab2b46d941953bf614e2617") {
        title
        body
        user {
            name
            email
        }
    }
  }
 <Query query={GET_BLOG}>...</Query>
const GET_BLOG=gql`
{
职位(id:“5ab2b46d941953bf614e2617”){
标题
身体
使用者{
名称
电子邮件
}
}
}
...

我让一切都正常工作了,我的问题是我有办法更改graphql端点url名称,所以我可以用像/graphql/post、/graphql/user这样的东西来代替graphql,我在graphql服务器中有这个方案,但如果我做两次调用,它只会在网络选项卡中返回两个/graphql,据我所知,graphql只使用一个端点url名称,在您的例子中,如果您想要分离端点,它就像REST路由一样

SERVER.applyMiddleware({
  app: APP, 
  path: '/newEndPoint'
});
在applyMiddleWare选项对象内设置路径属性。现在访问 图的
localhost:/newEndPoint