File tree Expand file tree Collapse file tree 3 files changed +8
-34
lines changed Expand file tree Collapse file tree 3 files changed +8
-34
lines changed Original file line number Diff line number Diff line change @@ -3,14 +3,7 @@ const { ApolloServer } = require('apollo-server');
33
44const gateway = new ApolloGateway ( {
55 serviceList : [
6- {
7- name : 'cms' ,
8- url : 'http://localhost:8000/graphql' ,
9- } ,
10- {
11- name : 'weather' ,
12- url : 'http://localhost:8100/graphql' ,
13- } ,
6+ // TODO (5) list locally running services
147 ] ,
158} ) ;
169
Original file line number Diff line number Diff line change @@ -2,6 +2,8 @@ const { gql } = require('apollo-server');
22
33const { getHello, resolveQuery } = require ( './fetcher' ) ;
44
5+ // TODO (3) update the user entity with the weather field and add an external reference
6+ // to the Weather entity
57const typeDefs = gql `
68 enum OrderDirection {
79 asc
@@ -26,17 +28,12 @@ const typeDefs = gql`
2628 direction: OrderDirection
2729 }
2830
29- type User @key(fields: "id") {
31+ type User {
3032 id: ID
3133 name: String
3234 username: String
3335 email: String
3436 location: String
35- weather: Weather
36- }
37-
38- extend type Weather @key(fields: "location") {
39- location: String! @external
4037 }
4138
4239 type UserEdge {
@@ -87,12 +84,9 @@ const typeDefs = gql`
8784 }
8885` ;
8986
87+ // TODO (4) define the new root level entry for the User entity and resolve weather there with the
88+ // parameters from the weather schema
9089const resolvers = {
91- User : {
92- weather ( user ) {
93- return { __typename : 'Weather' , location : user . location } ;
94- } ,
95- } ,
9690 Query : {
9791 hello : ( ) => getHello ( ) ,
9892 users : ( args ) => resolveQuery ( { table : 'users' , args : args || { } } ) ,
Original file line number Diff line number Diff line change @@ -2,16 +2,8 @@ const { gql } = require('apollo-server');
22
33const { getWeather } = require ( './fetcher' ) ;
44
5+ // TODO (1) write the new weather schema
56const typeDefs = gql `
6- type Weather @key(fields: "location"){
7- lat: String!
8- lon: String!
9- temp: String!
10- humidity: String!
11- pressure: String!
12- location: String!
13- }
14-
157 extend type Query {
168 weather(location: String!): Weather
179 }
@@ -23,12 +15,7 @@ const resolvers = {
2315 return getWeather ( args ) ;
2416 } ,
2517 } ,
26- Weather : {
27- /* eslint-disable-next-line no-underscore-dangle */
28- __resolveReference ( weather ) {
29- return getWeather ( { location : weather . location } ) ;
30- } ,
31- } ,
18+ // TODO (2) resolve reference on the root level
3219} ;
3320
3421module . exports = {
You can’t perform that action at this time.
0 commit comments