graphql-shorthand-parser
v0.0.6
Published
Parse GraphQL schemas from shorthand notation
Downloads
15
Readme
GraphQL Shorthand Parser
Parse GraphQL shorthand notation into a JSON object that can be used to auto-generate schema files.
Shorthand notation
// One of the films in the Star Wars Trilogy
enum Episode {
NEWHOPE
EMPIRE
JEDI
}
// A character in the Star Wars Trilogy
interface Character {
id: String!
name: String
friends: [Character]
appearsIn: [Episode]
}
// A humanoid creature in the Star Wars universe
type Human : Character {
id: String!
name: String
friends: [Character]
appearsIn: [Episode]
homePlanet: String
}
// A mechanical creature in the Star Wars universe
type Droid : Character {
id: String!
name: String
friends: [Character]
appearsIn: [Episode]
primaryFunction: String
}
type Query {
hero(episode: Episode): Character
human(id: String!): Human
droid(id: String!): Droid
}
Parsed notation to JSON
[
{
"type": "ENUM",
"name": "Episode",
"description": "One of the films in the Star Wars Trilogy",
"values": [
"NEWHOPE",
"EMPIRE",
"JEDI"
]
},
{
"type": "INTERFACE",
"name": "Character",
"description": "A character in the Star Wars Trilogy",
"fields": {
"id": {
"type": "String",
"required": true
},
"name": {
"type": "String"
},
"friends": {
"type": "Character",
"list": true
},
"appearsIn": {
"type": "Episode",
"list": true
}
}
},
{
"type": "TYPE",
"name": "Human",
"description": "A humanoid creature in the Star Wars universe",
"fields": {
"id": {
"type": "String",
"required": true
},
"name": {
"type": "String"
},
"friends": {
"type": "Character",
"list": true
},
"appearsIn": {
"type": "Episode",
"list": true
},
"homePlanet": {
"type": "String"
}
},
"interfaces": [
"Character"
]
},
{
"type": "TYPE",
"name": "Droid",
"description": "A mechanical creature in the Star Wars universe",
"fields": {
"id": {
"type": "String",
"required": true
},
"name": {
"type": "String"
},
"friends": {
"type": "Character",
"list": true
},
"appearsIn": {
"type": "Episode",
"list": true
},
"primaryFunction": {
"type": "String"
}
},
"interfaces": [
"Character"
]
},
{
"type": "TYPE",
"name": "Query",
"fields": {
"hero": {
"type": "Character",
"args": {
"episode": {
"type": "Episode"
}
}
},
"human": {
"type": "Human",
"args": {
"id": {
"type": "String",
"required": true
}
}
},
"droid": {
"type": "Droid",
"args": {
"id": {
"type": "String",
"required": true
}
}
}
}
}
]