GraphQL Zeus creates autocomplete client library for Javascript
or Typescript
which provides autocompletion for strongly typed queries.
Given the following schema Olympus Cards
Play with it
$ zeus https://faker.graphqleditor.com/aexol/olympus/graphql ./generated
import { Api } from "./generated/graphql-zeus"
MIT
Main usage of graphql zeus should be as a CLI.
Install globally
$ npm i -g graphql-zeus
Of course you can install locally to a project and then use as a npm command or with npx
$ zeus schema.graphql ./
It will also generate corresponding out.d.ts file so you can have autocompletion,
$ zeus schema.graphql ./ --ts
$ zeus https://faker.graphqleditor.com/aexol/olympus/graphql ./generated
import { Api } from './graphql-zeus';
// This will return Card object with ID only
const createCards = async () => {
let ZeusCard = await Api(
'https://faker.graphqleditor.com/aexol/olympus/graphql'
).Mutation.addCard({
card: {
name: 'Zeus',
description:
"Sky and Thunder god, rules olympus. Hasn't devoured any children. Zeus' father, Cronus ate all of his children except for Zeus.",
Attack: 10,
Defense: 5,
Children: 92 // YES!
}
})({
id: true
});
let DionysusCard = await Api(
'https://faker.graphqleditor.com/aexol/olympus/graphql'
).Mutation.addCard({
card: {
name: 'Dionysus',
description:
'Dionysus is the Greek god of wine, has the power to bring the dead back to life.',
Attack: 1,
Defense: 15,
Children: 9
}
})({
id: true,
name: true
});
// How to call graphql functions on objects
const [UpdatedDionysusCard, UpdatedZeusCard] = (await Api(
'https://faker.graphqleditor.com/aexol/olympus/graphql'
).Query.cardById({
cardId: DionysusCard.id
})({
attack: [
{
cardID: [ZeusCard.id]
},
{
id: true,
Attack: true,
Children: true,
Defense: true,
description: true,
name: true
}
]
})).attack;
console.log(UpdatedDionysusCard);
console.log(UpdatedZeusCard);
};
To run the example navigate to: ./example
and run
$ npm i
then run
$ npm run start
PROMISE_RETURNING_OBJECT = Api.[OPERATION_NAME].[OPERATION_FIELD](
...OPERATION_FIELD_PARAMS
)(
...RETURN PARAMS
)
Internal graphql type functions
PROMISE_RETURNING_OBJECT = Api.[OPERATION_NAME].[OPERATION_FIELD](
...OPERATION_FIELD_PARAMS
)(
...RETURN_PARAMS
[
{
...FUNCTION_PARAMS
},
{
...RETURN_FUNCTION_PARAMS
}
]
).then( object => object[FUNCTION_NAME] )
This will be rarely used, but here you are!
import { Parser,TreeToTS } from 'graphql-zeus';
const schemaFileContents = `
type Query{
hello: String!
}
schema{
query: Query
}
`
const typeScriptDefinition = TreeToTS.resolveTree(Parser.parse(schemaFileContents));
const jsDefinition = TreeToTS.javascript(Parser.parse(schemaFileContents));
Join our GraphQL Editor Channel
For a complete guide to contributing to GraphQL Editor, see the Contribution Guide.
- Fork this repo
- Create your feature branch: git checkout -b feature-name
- Commit your changes: git commit -am 'Add some feature'
- Push to the branch: git push origin my-new-feature
- Submit a pull request
Simplier approach to GraphQL parsing. Using graphql-js library and parsing AST to simplier types.