简体   繁体   English

如何使用graphql为angular2 + apollo-client创建服务

[英]How to create service for angular2 + apollo-client with graphql

I have no idea to create a service (like a api gateway) for send data that use apollo to my backend w/ graphql. 我不知道创建一个服务(如api网关)来发送使用apollo到我的后端w / graphql的数据。

If i dont have a service. 如果我没有服务。 All of my components that want to send or get data from backend w/ graphql always import those 2 我想要从后端发送或从graphql获取数据的所有组件总是导入那些2

import { Angular2Apollo } from 'angular2-apollo';
import gql from 'graphql-tag';

I try to create a service for that but query and mutation function in apollo have many property so my service can't warp all of many property. 我尝试为此创建一个服务,但是apollo中的查询和变异函数有很多属性,所以我的服务不能扭曲所有的属性。

Or it not be able to create service for that. 或者它无法为此创建服务。

Thanks. 谢谢。

Angular2 and Apollo Client are tools for creating a GraphQL client. Angular2和Apollo Client是用于创建GraphQL客户端的工具。 You need to create a separate app that is a GraphQL server. 您需要创建一个单独的应用程序,它是GraphQL服务器。

I suggest you create a new app and follow the instructions here: http://dev.apollodata.com/tools/graphql-server 我建议你创建一个新的应用程序,并按照这里的说明: http//dev.apollodata.com/tools/graphql-server

Then you can work on making your Angular2 app make requests to the GraphQL server. 然后,您可以使Angular2应用程序向GraphQL服务器发出请求。 For examples you can look here: http://dev.apollodata.com/angular2 例如,您可以在这里查看: http//dev.apollodata.com/angular2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM