Last active
December 6, 2016 18:47
-
-
Save jschroed91/ea20d14ed80e318f2fa9377dc967b5f1 to your computer and use it in GitHub Desktop.
react profile/index.js
This file contains hidden or 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
import React from 'react'; | |
import Profile from './Profile'; | |
import fetch from '../../core/fetch'; | |
import Layout from '../../components/Layout'; | |
const getQuery = url => (`{ | |
profile(url:"${url}") { | |
word_count | |
processed_language | |
personality { | |
...treeFields | |
children { | |
...treeFields | |
} | |
} | |
needs { | |
...treeFields | |
} | |
values { | |
...treeFields | |
} | |
behavior { | |
trait_id | |
name | |
category | |
percentage | |
} | |
warnings { | |
warning_id | |
message | |
} | |
word_count_message | |
} | |
} | |
fragment treeFields on TraitTreeNode { | |
trait_id | |
name | |
category | |
percentile | |
raw_score | |
} | |
`); | |
export default { | |
path: '/profile/:url+', | |
async action({ params }) { | |
const resp = await fetch('/graphql', { | |
method: 'post', | |
headers: { | |
Accept: 'application/json', | |
'Content-Type': 'application/json', | |
}, | |
body: JSON.stringify({ | |
query: getQuery(params.url), | |
}), | |
credentials: 'include', | |
}); | |
const { data } = await resp.json(); | |
if (!data || !data.profile) { | |
throw new Error('Failed to load the watson data.'); | |
} | |
return { | |
title: 'Watson Profile', | |
component: <Layout><Profile profile={data.profile} /></Layout>, | |
}; | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment