File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -24,6 +24,13 @@ const deleteOnUrl = url => getDataPromise(axios.delete(url));
2424
2525const editOnUrl = ( url , body ) => getDataPromise ( axios . patch ( url , body ) ) ;
2626
27+ const fetchUsersByFirstName = args => {
28+ const fetchUsersPromise = fetchFromUrl ( `${ BASE_URL } /users` ) ;
29+ return fetchUsersPromise . then ( allUsers =>
30+ _ . find ( allUsers , { firstName : args . firstName } )
31+ ) ;
32+ } ;
33+
2734const CompanyType = new GraphQLObjectType ( {
2835 name : "Company" ,
2936 fields : ( ) => ( {
@@ -55,12 +62,23 @@ const UserType = new GraphQLObjectType({
5562} ) ;
5663
5764const RootQuery = new GraphQLObjectType ( {
58- name : "RootQueryType " ,
65+ name : "RootQueryHere " ,
5966 fields : {
67+ hello : {
68+ // for more understanding basic example
69+ type : GraphQLString ,
70+ resolve ( ) {
71+ return "world" ;
72+ }
73+ } ,
6074 user : {
6175 type : UserType ,
62- args : { id : { type : GraphQLString } } ,
76+ args : { id : { type : GraphQLString } , firstName : { type : GraphQLString } } ,
6377 resolve ( parentValue , args ) {
78+ if ( ! args . id ) {
79+ // improvising query
80+ return fetchUsersByFirstName ( args ) ;
81+ }
6482 return fetchFromUrl ( `${ BASE_URL } /users/${ args . id } ` ) ;
6583 }
6684 } ,
@@ -75,7 +93,7 @@ const RootQuery = new GraphQLObjectType({
7593} ) ;
7694
7795const mutation = new GraphQLObjectType ( {
78- name : "mutation " ,
96+ name : "MutationHere " ,
7997 fields : {
8098 addUser : {
8199 type : UserType ,
You can’t perform that action at this time.
0 commit comments