swift-graphql

A GraphQL client that lets you forget about GraphQL.

MIT License

Stars
603
Committers
26

Bot releases are hidden (Show)

swift-graphql - SwiftGraphQL 2.0.0

Published by maticzav over 3 years ago

Hi there 👋🏿 ,

We've finally reached version 2.0.0! After several immensely successful beta releases of the next major SwiftGraphQL version, I think we are ready to ship. This version includes additions that profoundly change how the first version worked. To name a few, we've implemented subscriptions support, improved code-generation, built a CLI utility and more!

I hope you find this package as useful as I've seen it fun.

Before diving into all the changes, I'd like to thank @Amzd who helped me shape this library by implementing the subscription layer and adding some fantastic suggestions that make working with SwiftGraphQL more enjoyable. @Amzd thank you! ❤️

Our mission remains the same with every version - We want to build the most approachable Swift GraphQL client, that solves few things but solves them well.

Features

  • We've added support for subscriptions. To make a subscription selection, use the same pattern as before and create a socket, using the listen method.
  • We've added a CLI that you may use to generate the SwiftGraphQL code. You may download it using brew, mint or build it yourself using make.
  • Every structure in the schema that may be selected has type alias for better XCode IDE support. If, for example, you had a User type in the database and wanted to select a name out of it, you no longer have to make a phantom-type using Selection<User, String>. Instead, you can write Selection.User. Swift should infer the return type itself.

Internal changes

I've changed the code structure so that we expose another child-library - GraphQLAST. I haven't documented it, but it should be simple to use by following function annotations and inline docs.

Breaking Changes

  • When making a selection, field decoding might throw. That's why every assignment should be marked with try.
  • SwiftGraphQLCodegen no longer accepts an Options structure. Instead, you should forward scalars. Additionally SwiftGraphQLCodegen no longer writes to a file. Instead, it would be best if you used swift-graphql CLI tool as an alternative to build-phase script in version 1.x.x and 2.x.y-beta.z.
  • I've removed SG and SwiftGraphQL namespaces in favour of modules.

Future plans

I've started working on the documentation page. I think it's important that we promote the library more and hopefully land on some sponsors that would encourage this library's maintenance.

swift-graphql - SwiftGraphQL 2.0.0-beta.6

Published by maticzav over 3 years ago

This is a POC beta release. I've made significant changes to the internals of the API that still need to be documented.

swift-graphql - SwiftGraphQL 2.0.0-beta.5

Published by maticzav almost 4 years ago

This release introduces new optional() function modifier for Selection that lets you convert decoders that might return null into optional decoders that might return null.

Additionally, I've made some internal naming adjustments and nullable fields now return mock value by default instead of returning null.

swift-graphql - SwiftGraphQL 2.0.0-beta.4

Published by maticzav almost 4 years ago

This beta fixes operationName bug where the request wouldn't contain operationName variable in request body.

swift-graphql - SwiftGraphQL 2.0.0-beta.3

Published by maticzav almost 4 years ago

This beta lets you send named operations. You may do that by adding an optional operationName parameter in the send method.

SG.send(query, to: "http://localhost:4000", operationName: "Query") { result in
    if let data = try? result.get() {
        print(data)
    }
}
swift-graphql - SwiftGraphQL 2.0.0-beta.2

Published by maticzav almost 4 years ago

You might want to write a selection on the entire type from the selection composer itself. This usually happens if you have a distinct identifier reused in many types.

Consider the following scenario where we have an id field in Human type. There are many cases where we only query id field from the Human that's why we create a human id selection.

let humanId = Selection<HumanID, Objects.Human> {
    HumanID.fromString(try $0.id())
}

Now, we want to reuse that same selection when query a detailed human type. To do that, we can use selection helper method that lets you make a selection on the whole TypeLock from inside the selection.

struct Human {
    let id: HumanID
    let name: String
}

let human = Selection<Human, Objects.Human> {
    Human(
        id: try $0.selection(humanId),
        name: try $0.name()
    )
}

An alternative approach would be to manually rewrite the selection inside Human again.

let human = Selection<Human, Objects.Human> {
    Human(
        id: HumanID.fromString(try $0.id()),
        name: try $0.name()
    )
}

Having distinct types for ids of different object types is particularly useful in large projects as it gives you verification that you are not using a wrong identifier for a particular type of field. At first, this might seem useless and cumbersome, but it makes your code more robust once you get used to it.

swift-graphql - SwiftGraphQL 2.0.0-beta.1

Published by maticzav almost 4 years ago

This version includes utility functions for mapping a Selection and numerous improvements to internal data handling.

I've streamlined GraphQLResult structure so that it more accurately represents the return value.

Field accessors may now fail to reflect the possibility of a bad payload. This is a huge improvement over the previous approach since we no longer trigger a fatal error whenever the data is corrupt, but instead throw a bad payload error.

Additionally, we require that query selection is optional since it might fail. To prevent endless nullability wrappings, I've created a utility send function that wraps selection in nonNullOrFail selection.


This is a breaking release. To prevent version pollution, I'll keep some of the upcoming changes in the prerelease tag until we fix all the small changes internally.

swift-graphql - SwiftGraphQL 1.1.2

Published by maticzav almost 4 years ago

This release fixes the bug where nonNullOrFail selection would use mock data instead of throwing when data isn't there.

swift-graphql - SwiftGraphQL 1.1.1

Published by maticzav almost 4 years ago

Fixes the bug where errors wasn't a public property of a result.

swift-graphql - SwiftGraphQL 1.1.0

Published by maticzav almost 4 years ago

Ships utility functions for selecting nullable and list fields. Check the documentation for more information.

swift-graphql - SwiftGraphQL 1.0.0

Published by maticzav almost 4 years ago

This is the first stable release of SwiftGraphQL library. I'll continue to publish fixes as we discover them in our projects, but feel free to use the library. I'll use semantic versioning from now on.

swift-graphql - Networking

Published by maticzav almost 4 years ago

This release contains methods that you can use to send network requests besides other improvements.

swift-graphql - RC2

Published by maticzav almost 4 years ago

Includes bugfixes and improvements.

swift-graphql - RC1

Published by maticzav almost 4 years ago

Possibly the first stable release of this library.

Contains features like:

  • Object, Union, Interface selection;
  • Custom Scalars;
  • Automatic aliasing.

🎉

Package Rankings
Top 10.13% on Swiftpackageindex.com
Related Projects