Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hokaccha/graphql-cli
https://github.com/hokaccha/graphql-cli
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/hokaccha/graphql-cli
- Owner: hokaccha
- Created: 2016-02-12T08:11:29.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-02-12T08:11:39.000Z (almost 9 years ago)
- Last Synced: 2024-04-14T09:25:33.418Z (9 months ago)
- Language: JavaScript
- Size: 2.93 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# graphql-cli
**under development**.
Command line utilities for GraphQL.
## Examples
There is schema.js that is schema implementation of GraphQL.
```javascript
import {
GraphQLID,
GraphQLString,
GraphQLObjectType,
GraphQLList,
GraphQLSchema,
} from 'graphql';let users = [
{ id: "1", name: 'foo' },
{ id: "2", name: 'bar' },
{ id: "3", name: 'baz' },
];let userType = new GraphQLObjectType({
name: 'User',
fields: {
id: { type: GraphQLID },
name: { type: GraphQLString },
}
});let queryType = new GraphQLObjectType({
name: 'Query',
fields: {
users: {
type: new GraphQLList(userType),
resolve: () => new Promise(resolve => resolve(users)),
},
}
});export default new GraphQLSchema({ query: queryType });
```print schema:
```
$ graphql --schema-file schema.js --member default --babel --print-schema
type Query {
users: [User]
}type User {
id: ID
name: String
}
```execute query:
```
$ graphql --schema-file schema.js --member default --babel --query '{ users { id, name } }'
{
"data": {
"users": [
{
"id": "1",
"name": "foo"
},
{
"id": "2",
"name": "bar"
},
{
"id": "3",
"name": "baz"
}
]
}
}
```