All Projects → spring-media → Graphqlicious

spring-media / Graphqlicious

Licence: mit
A swift component with a DSL to declare GraphQL queries and to get string representations out of them

Programming Languages

swift
15916 projects
dsl
153 projects

Projects that are alternatives of or similar to Graphqlicious

Apollo Mocked Provider
Automatically mock GraphQL data with a mocked ApolloProvider
Stars: ✭ 70 (-7.89%)
Mutual labels:  graphql
Stickynotes
A Sticky Note Application
Stars: ✭ 74 (-2.63%)
Mutual labels:  apps
Hapi Fhir
🔥 HAPI FHIR - Java API for HL7 FHIR Clients and Servers
Stars: ✭ 1,197 (+1475%)
Mutual labels:  apps
Apollo Upload Client
A terminating Apollo Link for Apollo Client that allows FileList, File, Blob or ReactNativeFile instances within query or mutation variables and sends GraphQL multipart requests.
Stars: ✭ 1,176 (+1447.37%)
Mutual labels:  graphql
Facebook Graph Api
Get data using facebook graph API - V3.2
Stars: ✭ 73 (-3.95%)
Mutual labels:  graphql
React Hipstaplate
A ReactJS full-stack boilerplate based on typescript with ssr, custom apollo-server and huge stack of modern utilities which will help you to start your own project
Stars: ✭ 74 (-2.63%)
Mutual labels:  graphql
Graphql Batch
A query batching executor for the graphql gem
Stars: ✭ 1,164 (+1431.58%)
Mutual labels:  graphql
Apollo Tote
👜 A declarative approach to handling Apollo GraphQL queries in React
Stars: ✭ 76 (+0%)
Mutual labels:  graphql
Go Graphql Api
Source code for a tutorial on Medium I published - "Building an API with GraphQL and Go"
Stars: ✭ 73 (-3.95%)
Mutual labels:  graphql
Daptin
Daptin - Backend As A Service - GraphQL/JSON-API Headless CMS
Stars: ✭ 1,195 (+1472.37%)
Mutual labels:  graphql
Type Graphql Dataloader
TypeGraphQL + DataLoader + TypeORM made easy
Stars: ✭ 73 (-3.95%)
Mutual labels:  graphql
Graphql Schema Language Cheat Sheet
GraphQL Shorthand Notation Cheat Sheet
Stars: ✭ 1,181 (+1453.95%)
Mutual labels:  graphql
Pairhub
👩‍💻👨‍💻 Find remote pair programming partners
Stars: ✭ 74 (-2.63%)
Mutual labels:  graphql
Serverless Graphql Workshop
GraphQL and Serverless workshop
Stars: ✭ 70 (-7.89%)
Mutual labels:  graphql
Nextjs Strapi Boilerplate
🎨 Boilerplate for building applications using Strapi and Next.js
Stars: ✭ 76 (+0%)
Mutual labels:  graphql
Snowflaqe
A dotnet CLI tool to work with GraphQL queries: static query verification, type checking and code generating type-safe clients for F# and Fable.
Stars: ✭ 69 (-9.21%)
Mutual labels:  graphql
Graphql Persisted Document Loader
Webpack loader that adds a documentId to a compiled graphql document, which can be used when persisting/retrieving documents
Stars: ✭ 74 (-2.63%)
Mutual labels:  graphql
My Ios
List of applications and tools that make my iOS experience even more amazing
Stars: ✭ 1,202 (+1481.58%)
Mutual labels:  apps
Springboot Projects Fullstack
Spring Boot, JDBC, ORM, JPA, Hibernate, H2, MySQL, Oracle
Stars: ✭ 76 (+0%)
Mutual labels:  graphql
Flask Graphql
Adds GraphQL support to your Flask application.
Stars: ✭ 1,188 (+1463.16%)
Mutual labels:  graphql

GraphQLicious

GraphQLicious is a swift component that provides an intuitive and convenient way to build GraphQL queries and convert them easily to String representations.

[![iOS 8] (https://img.shields.io/badge/iOS%208%2B%20%7C%20MacOS%20X%2B%20%7C%20TV%20OS%20%7C%20Watch%20OS%202%2B-Compatible-brightgreen.svg)] ()

carthage cocoapods

swift3 license

travis codebeat codecov

Contents

Installation

Carthage

GraphQLicious supports Carthage. To install it, simply add the following line to your Cartfile

github "WeltN24/GraphQLicious"

CocoaPods

GraphQLicious is available through CocoaPods. To install it, simply add the following line to your Podfile

pod "GraphQLicious"

Submodule

If you don't use CocoaPods, you can still add GraphQLicious as a submodule, drag and drop GraphQLicious.xcodeproj into your project, and embed GraphQLicious.framework in your target.

  • Drag GraphQLicious.xcodeproj to your project
  • Select your app target
  • Click the + button on the Embedded binaries section
  • Add GraphQLicious.framework

Manual

You can directly drag and drop the needed files into your project, but keep in mind that this way you won't be able to automatically get all the latest features.
The files are contained in the Sources folder and work for the iOS framework

Usage

Query

Let's assume, we have the id of an article and we want to have the headline, body text and opener image of that article.

Our graphQL query for that will look like this:

query {
	test: content(id: 153082687){
		...contentFields
	}
}
fragment contentFields on Content {
	headline,
	body,
	image(role: "opener", enum: [this, that]){
		...imageContent
	}
}
fragment imageContent on Image {
	id
	url
}
fragment urlFragment on Image {
	 url (ratio: 1, size: 200) 
}

First, let's create a Fragment to fetch the contents of an image, namely the image id and the image url

let imageContent = Fragment(
	withAlias: "imageContent",
	name: "Image",
	fields: [
		"id",
		"url"
	]
)

Next, let's embed the Fragment into a Request that gets the opener image. Note: Argument values that are of type String are automatically represented with quotes. GraphQL also gives us the possibility to have custom enums as argument values. All you have to do is letting your enum implement ArgumentValue and you're good to go.

enum customEnum: String, ArgumentValue {
  case This = "this"
  case That = "that"
  
  private var asGraphQLArgument: String {
    return rawValue // without quotes
  }
}
    
let customEnumArgument = Argument(
  key: "enum",
  values: [
    customEnum.This,
    customEnum.That
  ]
)
let imageContentRequest = Request(
	name: "image",
	arguments: [
		Argument(key: "role", value: "opener"),
		customEnumArgument
	],
	fields: [
		imageContent
	]
)

So now we have a Request with an embedded Fragment. Let's go one step further.
If we want to, we can imbed that Request into another Fragment. (We can also embed Fragments into Fragments)
Additionally to the opener image with its id and url we also want the headline and body text of the article.

let articleContent = Fragment(
	withAlias: "contentFields",
	name: "Content",
	fields: [
		"headline",
		"body",
		imageContentRequest
	]
)

Finally, we put everything together as a Query. A Query always has a top level Request to get everything started, and requires all the Fragments that are used inside.

let query = Query(request: Request(
	withAlias: "test",
	name: "content",
	arguments: [
		Argument(key: "id", values: [153082687])
	],
	fields: [
		articleContent
	]),
	fragments: [articleContent, imageContent]
)

All we have to do now is to call create() on our Query and we're good to go.

print(query.create())

Mutation

Let's assume, we want to change our username and our age in our backend and we want to have the new name and age back to make sure everything went right.

Let's assume further, our server provides a mutating method editMe for exactly that purpose.

Our graphQL query for that will look like this:

mutation myMutation {
	editMe(
		name: "joe",
		age: 99
	)
	{
		name,
		age
	}
}

Let us first create the actual mutating function. We can use a Request for that. As Argument values we give information about which fields should be changed and what's the actual change

let mutatingRequest = Request(
      name: "editMe",
      arguments: [
      	Argument(name: "name", value: "joe"),
        Argument(name: "age", value: 99)
      ],
      fields: [
        "name",
        "age"
      ]
    )

Finally, we put everything together as a Mutation.

Mutations work just like Queries

let mutation = Mutation(
	withAlias: "myMutation",
	mutatingRequest: mutatingRequest
)

After we've done that we can create the request.

print(mutation.create())

Breaking changes

From 0.7 to 0.8

  • ReadingRequest is now simply Request
  • MutatingRequest has been removed, you can use Request instead
  • MutatingArgument has been removed, you can use Argument instead
  • MutatingValue and MutatingField have been removed, you can use Argument, or ObjectValue and ObjectKeyValuePair instead

Authors

GraphQLicious was made in-house by WeltN24

Contributors

Felix Dietz, [email protected], @podboq (@joemcbomb) on Github, @joemcbomb on Twitter

Vittorio Monaco, [email protected], @vittoriom on Github, @Vittorio_Monaco on Twitter

License

GraphQLicious is available under the MIT license. See the LICENSE files for more info.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].