An ANTLR4-based GraphQL parser for Clojure.
There are two different parsers – one for GraphQL query documents (as specified here), as well as one for GraphQL type system definitions. The latter ones do not seem to have a specification yet, so the parser implementation is currently based on the official "Schema and Types" guide available here.
(require '[alumbra.parser :as graphql])
The data produced by both parsers conforms to the specs given in alumbra.spec.
(graphql/parse-document
"query People($limit: Int = 10, $offset: Int = 0) {
people(limit: $limit, offset: $offset) {
name
friends { name }
}
}")
The resulting value will conform to the spec :alumbra/document
or contain
the key :alumbra/parser-errors
.
(graphql/parse-schema
"type Person {
name: String!
}
type QueryRoot {
people(limit: Int, offset: Int): [Person]
}
schema { query: QueryRoot }")
The resulting value will conform to the spec :alumbra/schema
or contain
the key :alumbra/parser-errors
.
This project uses alumbra.generators and test.check to verify parser functionality. You can run all tests using:
$ lein test
MIT License
Copyright (c) 2016 Yannick Scherer
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close