All notable changes to
the dillonkearns/elm-graphql elm package
will be documented in this file.
The format is based on Keep a Changelog and this project adheres to Semantic Versioning.
- (MAJOR API change) Fix order of arguments for Http pipeline function,
withOperationName(fixes #254). - (MAJOR API change) Switch
discardParsedErrorDatafrom returning a()to an unconstraineda. This makes it a little more flexible for users in terms of the types it allows, without changing the behavior. See #245 (thank you @Jayshua!). - (MAJOR API change) fix typo in internal function name (
exhuastiveFragmentSelection->exhaustiveFragmentSelection).
- Expose
Graphql.Http.withOperationNamefunction (which was mistakenly left out last release).
Graphql.Http.withOperationNameallows you to (optionally) add operation names to your GraphQL queries (thank you @asterite for your PR! dillonkearns#195)
- Parse pre-execution GraphQL response that has "error" but no "data" (see #168).
- Added
SeletionSet.foldl - Added
OptionalArgument.fromMaybeWithNull
- Don't use field aliases for __typename fields (see PR #121).
SelectionSet.listlets you combine aListofSelectionSet value typeLocks into a singleSelectionSet (List value) typeLock.SelectionSet.dictlets you combine aListof(String, SelectionSet value typeLock)s into a singleSelectionSet (Dict String value) typeLock. TheStrings in the list are used as the key in theDict.- Expose type
Graphql.Codec(for use with the--scalar-codecsCLI flag, see this example).
- Expose type
Graphql.Http.HttpError
-
elm/http@2.0.0removed some important data fromHttp.Error. It's now just (BadStatus Intrather thanBadStatus (Response String)). See the type definitions here: https://package.elm-lang.org/packages/elm/http/1.0.0/Http#Error https://package.elm-lang.org/packages/elm/http/latest/Http#ErrorIn order to allow
dillonkearns/elm-graphqlusers to capture the body of responses with a bad status, we need to do a major version bump.In a nutshell, this change introduces a custom type that looks like this:
module Graphql.Http.Error exposing -- ..
type alias Error parsedData =
RawError parsedData HttpError
type RawError parsedData httpError
= GraphqlError (GraphqlError.PossiblyParsedData parsedData) (List GraphqlError.GraphqlError)
| HttpError httpError
type HttpError
= BadUrl String
| Timeout
| NetworkError
| BadStatus Http.Metadata String
| BadPayload Json.Decode.ErrorSee the full details here: dillonkearns#89
Note that this will only require you to change your code if you were destructuring
the Graphql.Http.HttpError values. And the changes introduce a function to map
into the old type easily:
withSimpleHttpError : Result (Error parsedData) decodesTo -> Result (RawError parsedData Http.Error) decodesToWell, not exactly the old type, the old type was Graphql.Http.Error parsedData,
the new type is written out as Graphql.Http.RawError parsedData Http.Error,
but it would contains the same data as before.
Graphql.Http.fromHttpErrorwas removed as it no longer makes sense with the default type wrappingGraphql.Http.HttpErrorinstead ofHttp.Error. See theGraphql.Http.withSimpleHttpErrordocs if you are looking to combine a Graphql response with an Http response.- Removed
ignoreParsedErrorDatato avoid confusion. It's easier to usediscardParsedErrorData, use that function instead. It maps the entire result so you don't have to use it in combination withGraphql.Http.mapError.
- Only the internal code changed in this release, so you won't need to do anything to upgrade your own code besides re-running the latest CLI tool. The change includes the type information of a field in its field alias hash. Since the alias is now unique to each field's type and argument values, you can no longer encounter validation errors when you build up a query using unions or interfaces that include fields with the same names but different types. See dillonkearns#95 for more details.
-
The
Fieldmodule has been removed. With this change, think of aFieldas just a special case of aSelectionSet. TheSelectionSetis now used for both a single element or multiple (much like a singleCmd msgor multiple withCmd.batch [cmd1, cmd2]). This means that any functions you called onFieldbefore are now inSelectionSet(so it'sSelectionSet.nonNullOrFail,SelectionSet.map, etc). The latest docs page forSelectionSetnow has a nice tutorial in it that walks you through the new way thatSelectionSets work. If you're trying to wrap your head around the new design, I highly recommend you read this page!To migrate to the new version, just follow these steps:
- Find and delete all calls to
import Graphql.Fieldin your code entirely - Anywhere you called
SelectionSet.fieldSelectioncan simply be removed now. - Anywhere you called
Field.map,mapOrFail, etc., is justSelectionSet.map, etc. now. - Remove any calls to
<GeneratedModule>.selectionand replace it withSelectionSet.succeed(for Union types, theselectionfunction has been renamed tofragments, see the last point below). - Any annotations which were
Field decodesTo typeLock, simply change them toSelectionSet decodesTo typeLock
- Find and delete all calls to
-
The
.selectionfunction for Unions has been renamed to.fragmentsto be consistent with the naming for Interfaces.
- Add
SelectionSet.mapNfunctions for an alternate syntax to the pipeline syntax (starting a pipeline withSelectionSet.succeed). - New
SeletionSet.withDefault. Just a convenience function which is equivalent toSelectionSet.map Maybe.withDefault.
- The
withCredentialswas inverted with release 1.4.0. So it would use theHttp.riskyandHttp.riskyTaskversions if you didn't callwithCredentials, and it would use the regularHttp.requestandHttp.taskbuilders if you did. Thank you @kyasu1 for reporting the problem! See #97.
- Add new internal builder function, for use with the new generated code for building exhaustive Union and Interface fragments. See this diff to understand the changes and how to migrate: e530d94.
- Bump underlying
elm/httpandelm/jsonpackages.
- Add
Graphql.Http.sendWithTrackerfunction, see theHttp.requestdocs for details and functions to track Http requests in Elm.
- Add
discardParsedErrorDatato make it easier to map errors into a type that can be easily merged together (something that looks likeResult (Error ()) decodesTo). - Add
parseableErrorAsSuccess, which treats any GraphQL errors like successful responses (throws away the GraphQL error) as long as it is able to successfully run the decoder (it won't be able to if the data returned is partial).
SelectionSet.withFragmentallows you to include fields from aSelectionSetwhen you are defining aSelectionSet. This is a nice tool for modularizing your queries! Check out an example in action.SelectionSet.map2allows you to combine twoSelectionSets into one.- New
OptionalArgument.mapfunciton, thanks Romario! (See PR #73).
- The generated selection sets now will include at least a
__typenameto ensure they are valid (empty selection sets are invalid in GraphQL). Previously you could get an invalid GraphQL query if you usedSelectionSet.hardcoded. - (Internal implementation details, not public facing though the generated
queries will look slightly different now) - The
aliasgeneration has changed to be independent of surrounding context. The new algorithm will generate analiasfor any field if and only if that field has arguments. You can read more about the details and rationale on this thread.
- Extracted
scalarDecoderconstant and moved to module in thedillonkearns/elm-graphqlpackage. This is only used in generated code. This change allows us to remove allDebug.toStringcalls in generated code so that users can compile their code with the--optimizeflag. This resolves #68.
Take a look at the dillonkearns/elm-graphql Elm 0.19 upgrade guide.
- Subscriptions Low-Level Data-Transfer Layer As before, this library will
generate code based on the subscriptions defined in your GraphQL schema.
And you will be able to use
Graphql.Document.serializeSubscriptionto get aStringthat you can send over to your server when you open a subscription. Then you'll be able to use theGraphql.Document.decoderfrom your subscription to decode the JSON responses from the server. What's been removed is just the low level protocols for doing the websocket connection. As per this issue, this responsibility will be moved out of the coredillonkearns/elm-graphqlpackage in order to decouple this library from the low-level details which differ between different GraphQL server implementations.
The low-level data transfer logic for connecting over websockets to a subscription has been removed from this package. dillonkearns#43
- Rename package from
dillonkearns/graphqelmtodillonkearns/elm-graphqlto follow the elm literal naming convention (see issue #23).
BELOW THIS IS FOR dillonkearns/graphqelm (before the rename to dillonkearns/elm-graphql)
- Add
Selectionset.fieldSelectionfunction to concisely turn a singleFieldinto aSelectionSet. Thanks to anagrius for the suggestion!
- Add
mapErrorandignoreParsedErrorDatafunctions to allow you to do more manipulation ofParsedDatawithin Error data (fixes #52).
- Responses are errors if any data is present in
errorsfield in response. Thedatafield from the response is also included inGraphqlErrors now so you can inspect the data upon failure. Here is a summary of how this will effect your code:- Before,
dillonkearns/elm-graphqlalways treated responses where it could parse the response as success. - Now, it will treat responses where
errorsare present as an error regardless of whether it is able to parse the responsedata. - Users will need to add a type variable to their error type as errors may contain parsed data now (so
RemoteData (Graphql.Http.Error) Response->RemoteData (Graphql.Http.Error Response) Response) - For more context, here's the Github issue: dillonkearns#48 (comment)
- For an example, see https://github.com/dillonkearns/elm-graphql/blob/30be3570f52f5fd73055321e1a998c4082db32cf/examples/src/ErrorHandling.elm#L80-L107
- Before,
- Add
SelectionSet.succeedto provide a hardcoded value as the result of a SelectionSet.
- Expose GraphQL response decoder publicly.
- Update model to allow more flexibility based on #32.
- Add functions for transforming
Fields usingResults. These functions are handy for converting values into types likeDateTimes but can cause your entire response to error when decoding if any incorrect assumptions are made so they should be used with extreme care.
- Remove
AlwaysPostsinceGraphql.Http.queryRequestnow always uses POST. Added option toGetWhenShortEnough.
- Add
Graphql.OptionalArgument.fromMaybe. - Add
SelectionSet.map.
- Always use POST when sending query requests since some APIs like Github don't support GET (see https://developer.github.com/v4/guides/forming-calls/#communicating-with-graphql).
- Add
Graphql.Http.withQueryParams.
- Use GET requests by default when sending a query request, unless the resulting
url would be over 2000 characters.
queryParamsForceMethodallows you to specify a method when needed. - Rename
Graphql.Httpfunctions frombuildMutationRequest=>mutationRequestandbuildQueryRequest=>queryRequestto sound more declarative and concise. - Extract Subscription.Protocol module which encapsulates the details about low-level subscription communication for a given framework. The module includes an implementation for Rails and Absinthe/Rhoenix, or custom.
- Add experimental subscriptions module and example.
- Add
Graphql.Http.toTask. - Expose
Graphql.Http.withCredentials.
- Rename
FieldDecodertype and module toFieldto match GraphQL domain language more closely.
- Add
hardcodedfunction to add arbitrary constants alongsidewithcalls.
- Expose Http.Error constructors.
- Remove unused elm package dependencies.
- Add missing
Encode.floatfunction. Without this, APIs with float arguments would have compilation errors.
- Modules that are used only by generated code are now under
Graphql.Internalto make it more clear in the documentation.
- Encode functions to support generated code for input objects. There is now no reason for users to consume the Encode module directly! It's all done under the hood by the generated code.
- Fix bug that excluded arguments when serializing leaves in document.