From f813a7719405dca0d8c2c3e096201a40624bb866 Mon Sep 17 00:00:00 2001 From: Belen Curcio Date: Fri, 20 Jan 2017 18:48:35 -0300 Subject: [PATCH] queries and mutations --- client/coral-embed-stream/src/Embed.js | 30 +++++-------------- .../src/graphql/mutations/index.js | 20 +++++++++++++ .../src/graphql/queries/index.js | 12 ++++++++ graph/resolvers/comment.js | 7 +++++ graph/typeDefs.js | 1 + 5 files changed, 47 insertions(+), 23 deletions(-) create mode 100644 client/coral-embed-stream/src/graphql/mutations/index.js create mode 100644 client/coral-embed-stream/src/graphql/queries/index.js diff --git a/client/coral-embed-stream/src/Embed.js b/client/coral-embed-stream/src/Embed.js index a72d8c1ad..c1690aeb7 100644 --- a/client/coral-embed-stream/src/Embed.js +++ b/client/coral-embed-stream/src/Embed.js @@ -1,10 +1,10 @@ import React, {Component, PropTypes} from 'react'; import Pym from 'pym.js'; -import {graphql, compose} from 'react-apollo'; +import {compose} from 'react-apollo'; import {connect} from 'react-redux'; -import STREAM_QUERY from './graphql/queries/streamQuery.graphql'; -import POST_COMMENT from './graphql/mutations/postComment.graphql'; +import {postComment} from './graphql/mutations' +import {queryStream} from './graphql/queries' import { @@ -209,6 +209,7 @@ const mapDispatchToProps = dispatch => ({ // appendItemArray: (item, property, value, addToFront, itemType) => dispatch(appendItemArray(item, property, value, addToFront, itemType)), // handleSignInDialog: () => dispatch(authActions.showSignInDialog()), logout: () => dispatch(logout()), + dispatch: d => dispatch(d) }); // Initialize GraphQL queries or mutations with the `gql` tag @@ -217,24 +218,7 @@ const pym = new Pym.Child({polling: 100}); let url = pym.parentUrl; export default compose( - graphql(STREAM_QUERY, { - options: {variables: {asset_url: url}}, - props: props => props, - }), - graphql(POST_COMMENT, { - props: ({mutate}) => ({ - postItem: ({asset_id, body}) => { - mutate({ - variables: { - asset_id, - body, - parent_id: null - } - }).then(({data}) => { - console.log('it workt'); - console.log(data); - }); - }}), - }), - connect(mapStateToProps, mapDispatchToProps) + connect(mapStateToProps, mapDispatchToProps), + postComment(), + queryStream() )(Embed); diff --git a/client/coral-embed-stream/src/graphql/mutations/index.js b/client/coral-embed-stream/src/graphql/mutations/index.js new file mode 100644 index 000000000..66cb97d21 --- /dev/null +++ b/client/coral-embed-stream/src/graphql/mutations/index.js @@ -0,0 +1,20 @@ +import { graphql } from 'react-apollo'; +import POST_COMMENT from './postComment.graphql'; + +export const postComment = () => + graphql(POST_COMMENT, { + props: ({mutate}) => ({ + postItem: ({asset_id, body}) => { + mutate({ + variables: { + asset_id, + body, + parent_id: null + } + }).then(({data}) => { + console.log('it workt'); + console.log(data); + }); + }}), + }); + diff --git a/client/coral-embed-stream/src/graphql/queries/index.js b/client/coral-embed-stream/src/graphql/queries/index.js new file mode 100644 index 000000000..d3b3bdb86 --- /dev/null +++ b/client/coral-embed-stream/src/graphql/queries/index.js @@ -0,0 +1,12 @@ +import { graphql } from 'react-apollo'; +import STREAM_QUERY from './streamQuery.graphql'; +import Pym from 'pym.js'; + +const pym = new Pym.Child({polling: 100}); +let url = pym.parentUrl; + +export const queryStream = () => + graphql(STREAM_QUERY, { + options: {variables: {asset_url: url}}, + props: props => props, + }); diff --git a/graph/resolvers/comment.js b/graph/resolvers/comment.js index 2fdf6f0dd..1b1c10046 100644 --- a/graph/resolvers/comment.js +++ b/graph/resolvers/comment.js @@ -7,6 +7,13 @@ const Comment = { }, actions({id}, _, {loaders}) { return loaders.Actions.getByID.load(id); + }, + status({status}) { + + // Because the status can be `null`, we do this check. + if (status) { + return status.toUpperCase(); + } } }; diff --git a/graph/typeDefs.js b/graph/typeDefs.js index aadc7f57d..9889815d5 100644 --- a/graph/typeDefs.js +++ b/graph/typeDefs.js @@ -20,6 +20,7 @@ type Comment { user: User replies(limit: Int = 3): [Comment] actions: [ActionSummary] + status: String } enum ITEM_TYPE {