This repository has been archived by the owner on Dec 17, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(graphql): Add fitness activities
Added beginning of fitness activities schema. Added resolve item functionality to call 'next' properties when needed to get correct count of items. Set default item count to 25.
- Loading branch information
Simon Wears
committed
Mar 17, 2017
1 parent
aea4923
commit 2679b4f
Showing
9 changed files
with
110 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{ | ||
"SERVER_START": "Server started on port %{port}" | ||
"SERVER_START": "Server started on port %{port}", | ||
"RUNKEEPER_REQUEST": "Request made to Runkeeper API %{endpoint}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const graphql = require('graphql'); | ||
const GraphQLObjectType = graphql.GraphQLObjectType; | ||
const GraphQLString = graphql.GraphQLString; | ||
const GraphQLList = graphql.GraphQLList; | ||
const GraphQLInt = graphql.GraphQLInt; | ||
const GraphQLBoolean = graphql.GraphQLBoolean; | ||
|
||
const resolveItems = require('../helpers/resolve-items'); | ||
const resolve = resolveItems.resolve; | ||
const args = resolveItems.args; | ||
|
||
const FitnessItem = new GraphQLObjectType({ | ||
name: 'FitnessItem', | ||
fields: { | ||
type: {type: GraphQLString}, | ||
start_time: {type: GraphQLString}, | ||
utc_offset: {type: GraphQLInt}, | ||
total_distance: {type: GraphQLInt}, | ||
duration: {type: GraphQLInt}, | ||
total_calories: {type: GraphQLInt}, | ||
source: {type: GraphQLString}, | ||
entry_mode: {type: GraphQLString}, | ||
tracking_mode: {type: GraphQLString}, | ||
has_path: {type: GraphQLBoolean}, | ||
uri: {type: GraphQLString} | ||
} | ||
}); | ||
|
||
module.exports = new GraphQLObjectType({ | ||
name: 'FitnessActivities', | ||
fields: { | ||
size: {type: GraphQLInt}, | ||
items: { | ||
type: new GraphQLList(FitnessItem), | ||
args, | ||
resolve | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const fetch = require('./fetch'); | ||
const graphql = require('graphql'); | ||
const GraphQLInt = graphql.GraphQLInt; | ||
|
||
module.exports = { | ||
|
||
args: { | ||
count: {type: GraphQLInt} | ||
}, | ||
|
||
resolve (parent, args, req) { | ||
|
||
return new Promise(resolve => { | ||
|
||
const opts = Object.assign({ | ||
count: 25 | ||
}, args); | ||
|
||
let items = parent.items; | ||
|
||
function getItems (count, next) { | ||
return new Promise(resolve => { | ||
|
||
fetch(next, req).then(data => { | ||
items = items.concat(data.items); | ||
|
||
if (count > items.length && data.next) { | ||
return getItems(count, data.next); | ||
} | ||
|
||
}).then(resolve); | ||
|
||
}); | ||
} | ||
|
||
if (opts.count > items.length && parent.next) { | ||
|
||
getItems(opts.count, parent.next).then(() => { | ||
resolve(items.slice(0, opts.count)); | ||
}); | ||
|
||
} else { | ||
resolve(items.slice(0, opts.count)); | ||
} | ||
|
||
}); | ||
|
||
} | ||
}; |