GraphQLer is a Swift library for generating GraphQL documents (i.e. things you can send to a server.) It follows the June 2018 spec. It does not do networking, data binding, or parsing.
It’s a pure Swift library with no dependencies beyond the standard library, so it should be usable in any environment where you can use Swift.
Usage
For details about the API, see the source or docs.
GraphQLer implements a straightforward mapping from the types in GraphQL specs to Swift types. The types are the same you’ll find in the spec: Document, ExecutableDefinition, Operation, Field, Selection, SelectionSet, etc. This means that it should be easy enough if you know the format, but it can be verbose. You may want to add some layers on top of it to facilitate the use of the API you need.
Using the GraphQLer types and convenience methods, you could write something like this:
If you’re building a lot of different GraphQL documents, it’s probably a good idea to add some helpers for the things you care about. If you do it with extensions, you get autocompletion support in Xcode:
You can try running these examples yourself in the included Xcode playgrounds. If you open Package.swift in Xcode, you should also see the playgrounds.
GraphQLer
GraphQLer is a Swift library for generating GraphQL documents (i.e. things you can send to a server.) It follows the June 2018 spec. It does not do networking, data binding, or parsing.
It’s a pure Swift library with no dependencies beyond the standard library, so it should be usable in any environment where you can use Swift.
Usage
For details about the API, see the source or docs.
GraphQLer implements a straightforward mapping from the types in GraphQL specs to Swift types. The types are the same you’ll find in the spec: Document, ExecutableDefinition, Operation, Field, Selection, SelectionSet, etc. This means that it should be easy enough if you know the format, but it can be verbose. You may want to add some layers on top of it to facilitate the use of the API you need.
Using the GraphQLer types and convenience methods, you could write something like this:
If you’re building a lot of different GraphQL documents, it’s probably a good idea to add some helpers for the things you care about. If you do it with extensions, you get autocompletion support in Xcode:
You can try running these examples yourself in the included Xcode playgrounds. If you open
Package.swift
in Xcode, you should also see the playgrounds.