Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Sep 2, 2022. It is now read-only.

Commit 15ffb37

Browse files
author
Chris Nelson
committed
Stuff is working agains GraphCool example project
1 parent cb03e33 commit 15ffb37

File tree

9 files changed

+26343
-23
lines changed

9 files changed

+26343
-23
lines changed

‎README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,9 @@ This project was bootstrapped with [Create React App](https://github.com/faceboo
1717
npm install
1818
npm start
1919
```
20-
This assumes you are running your GraphQL server on http://localhost:4000/grapqhl. To
21-
change this, edit `src/store.js`.
20+
21+
## GraqhCool
22+
23+
I've been using [GraphCool](http://graph.cool) to play around with creating a GraphQL schema to test
24+
against. Right now this is configured in src/graphqlCoolClient.js. It's easy enough
25+
to create GraphCool project and try it out, just change the endpoint.

‎src/ArgsForm.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { Component } from 'react';
2-
import { findInputFields } from './graphql_utils';
2+
import { findInputFields,findType,findEffectiveType,findEnumValues,isEnum } from './graphql_utils';
33

44
class ArgsForm extends Component {
55

@@ -26,10 +26,27 @@ class ArgsForm extends Component {
2626
}
2727
}
2828

29+
renderEnumField(arg, prefix) {
30+
const enumValues = findEnumValues(this.props.schema, findEffectiveType(arg.type).name);
31+
return (
32+
<div>
33+
<label>{arg.name}</label>
34+
<select name={arg.name} onChange={ (event)=> this.argValueChange(prefix.concat(arg.name) : arg.name, event.target.value)}>
35+
{ enumValues.map( (enumValue) => (
36+
<option>{enumValue.name}</option>
37+
))
38+
}
39+
</select>
40+
</div>
41+
);
42+
}
43+
44+
2945
renderArgField(arg, prefix=[]) {
30-
console.log(arg);
3146
if (arg.type.kind == "INPUT_OBJECT") {
3247
return this.renderInputObjectFields(arg, prefix);
48+
} else if (isEnum(arg)) {
49+
return this.renderEnumField(arg, prefix);
3350
} else {
3451
return this.renderSimpleArgField(arg, prefix);
3552
}

‎src/Query.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { Component } from 'react';
22
import { connect } from 'react-redux';
3-
import { findQueryType, findQueryField, isListQuery } from './graphql_utils';
3+
import { findQueryReturnType, findQueryField, isListQuery } from './graphql_utils';
44
import { executeQueryAction } from './actions/executeQuery';
55
import { getSchema, getQueryResult } from './reducers';
66
import QueryResultsTable from './QueryResultTable';
@@ -15,11 +15,11 @@ const displayQueryResult = (queryField, queryResult) => {
1515
}
1616
};
1717

18-
const Query = ({params, queryType, queryField, executeQuery, queryResult}) => {
18+
const Query = ({params, queryType, queryField, schema,executeQuery, queryResult}) => {
1919
return (
2020
<div>
2121
<h3>{params.queryName}</h3>
22-
<QueryArgsForm args={queryField.args} onExecute={executeQuery} buttonLabel="Execute Query"/>
22+
<QueryArgsForm schema={schema}args={queryField.args} onExecute={executeQuery} buttonLabel="Execute Query"/>
2323
{ queryResult ? displayQueryResult(queryField, queryResult) : '' }
2424
</div>
2525
);
@@ -28,8 +28,9 @@ const Query = ({params, queryType, queryField, executeQuery, queryResult}) => {
2828
const mapStateToProps = (state, ownProps) => {
2929
return {
3030
queryField: findQueryField(getSchema(state), ownProps.params.queryName),
31-
queryType: findQueryType(getSchema(state), ownProps.params.queryName),
32-
queryResult: getQueryResult(state)
31+
queryType: findQueryReturnType(getSchema(state), ownProps.params.queryName),
32+
queryResult: getQueryResult(state),
33+
schema: getSchema(state)
3334
};
3435
}
3536

‎src/actions/executeQuery.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const queryExecutedAction = createAction('queryExecuted');
66
export const clearQueryResultAction = createAction('clear query result');
77

88
export const executeQueryAction = (queryName, args) => {
9-
console.log('executing query'+queryName);
9+
console.log('executing query',queryName,args);
1010
return (dispatch, getState, client) => {
1111
console.log('in thunk');
1212
const schema = getSchema(getState());

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /