File tree Expand file tree Collapse file tree 5 files changed +2040
-1
lines changed Expand file tree Collapse file tree 5 files changed +2040
-1
lines changed Original file line number Diff line number Diff line change @@ -42,3 +42,6 @@ app.*.map.json
42
42
43
43
# Exceptions to above rules.
44
44
! /packages /flutter_tools /test /data /dart_dependencies_test /** /.packages
45
+
46
+ # Server dependencies (should be installed by running npm install within the server folder)
47
+ server /node_modules /
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ void main() {
14
14
home: Scaffold (
15
15
backgroundColor: Colors .grey.shade200,
16
16
appBar: StyledAppBar (),
17
- body: StatsScreen (),
17
+ body: HomeScreen (),
18
18
bottomNavigationBar: StyledBottomNavigationBar (),
19
19
),
20
20
),
Original file line number Diff line number Diff line change
1
+ const { GraphQLServer } = require ( 'graphql-yoga' ) ;
2
+ const fetch = require ( 'node-fetch' ) ;
3
+
4
+ const typeDefs = `
5
+ type Query {
6
+ hello(name: String): String!
7
+ getPerson(id: Int!): Person
8
+ }
9
+
10
+ type Film {
11
+ title: String,
12
+ episode_id: String,
13
+ }
14
+
15
+ type Person {
16
+ name: String
17
+ height: String
18
+ mass: Int
19
+ hair_color: String
20
+ skin_color: String,
21
+ films: [Film],
22
+ }
23
+ ` ;
24
+
25
+ const resolvers = {
26
+ Person : {
27
+ films : ( person ) => {
28
+ const filmsPromises = person . films . map ( async url => {
29
+ const response = await fetch ( url ) ;
30
+ return response . json ( ) ;
31
+ } ) ;
32
+
33
+ return Promise . all ( filmsPromises ) ;
34
+ }
35
+ } ,
36
+ Query : {
37
+ hello : ( _ , { name } ) => { return `Hello ${ name || 'World' } ` } ,
38
+ getPerson : async ( _ , { id } ) => {
39
+ const response = await fetch ( `https://swapi.dev/api/people/${ id } /` ) ;
40
+ return response . json ( ) ;
41
+ }
42
+ }
43
+ }
44
+
45
+ const server = new GraphQLServer ( { typeDefs, resolvers } ) ;
46
+ server . start ( ( ) => console . log ( 'Server is running on localhost:4000' ) ) ;
You can’t perform that action at this time.
0 commit comments