Skip to content

Instantly share code, notes, and snippets.

@jschroed91
Last active December 6, 2016 18:47
Show Gist options
  • Save jschroed91/ea20d14ed80e318f2fa9377dc967b5f1 to your computer and use it in GitHub Desktop.
Save jschroed91/ea20d14ed80e318f2fa9377dc967b5f1 to your computer and use it in GitHub Desktop.
react profile/index.js
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