graphql-client 1.2.3 → 1.2.4
raw patch · 11 files changed
+126/−5 lines, 11 filesdep +processdep ~aesondep ~aeson-schemasdep ~bytestringPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies added: process
Dependency ranges changed: aeson, aeson-schemas, bytestring, file-embed, http-client, http-client-tls, http-types, mtl, optparse-applicative, path, path-io, template-haskell, text, transformers, typed-process, unliftio-core
API changes (from Hackage documentation)
- Data.GraphQL.Bootstrap: (.=) :: (KeyValue kv, ToJSON v) => Key -> v -> kv
+ Data.GraphQL.Bootstrap: (.=) :: (KeyValue e kv, ToJSON v) => Key -> v -> kv
- Data.GraphQL.Bootstrap: data Text
+ Data.GraphQL.Bootstrap: data () => Text
Files
- CHANGELOG.md +4/−0
- graphql-client.cabal +11/−3
- js/graphql-codegen-haskell.js +5/−2
- test/Data/GraphQL/Test/Generation/TestGeneration.hs +18/−0
- test/Data/GraphQL/Test/Generation/codegen.yml +7/−0
- test/Data/GraphQL/Test/Generation/queries/basic.graphql +8/−0
- test/Data/GraphQL/Test/Generation/queries/duplicate-names.graphql +11/−0
- test/Data/GraphQL/Test/Generation/run.sh +24/−0
- test/Data/GraphQL/Test/Generation/schema.graphql +20/−0
- test/Data/GraphQL/Test/Generation/src/Example/Scalars.hs +16/−0
- test/Main.hs +2/−0
CHANGELOG.md view
@@ -1,3 +1,7 @@+# v1.2.4++* Fix ambiguous field name error with same argument name in multiple queries ([#86](https://github.com/brandonchinn178/graphql-client/issues/86))+ # v1.2.3 * Add support for GHC 9.8
graphql-client.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: graphql-client-version: 1.2.3+version: 1.2.4 synopsis: A client for Haskell programs to query a GraphQL API description: A client for Haskell programs to query a GraphQL API. category: Graphql@@ -19,6 +19,12 @@ extra-source-files: README.md CHANGELOG.md+ test/Data/GraphQL/Test/Generation/run.sh+ test/Data/GraphQL/Test/Generation/src/Example/Scalars.hs+ test/Data/GraphQL/Test/Generation/queries/basic.graphql+ test/Data/GraphQL/Test/Generation/queries/duplicate-names.graphql+ test/Data/GraphQL/Test/Generation/schema.graphql+ test/Data/GraphQL/Test/Generation/codegen.yml ./js/graphql-codegen-haskell.js ./js/graphql-codegen-haskell-fallback.js ./js/mocks/__utils.js@@ -64,11 +70,11 @@ ghc-options: -Wall -Wcompat -Wincomplete-record-updates -Wincomplete-uni-patterns -Wnoncanonical-monad-instances -Wunused-packages build-depends: base <5- , bytestring <0.12+ , bytestring <0.13 , file-embed <0.1 , optparse-applicative <0.19 , path <0.10- , path-io <2+ , path-io >=1.3.3 && <2 , template-haskell <3 , typed-process <0.3 default-language: Haskell2010@@ -77,6 +83,7 @@ type: exitcode-stdio-1.0 main-is: Main.hs other-modules:+ Data.GraphQL.Test.Generation.TestGeneration Data.GraphQL.Test.Monad.Class Data.GraphQL.Test.TestQuery Data.GraphQL.Test.TestUtils@@ -90,6 +97,7 @@ , base , graphql-client , mtl+ , process , tasty , tasty-hunit default-language: Haskell2010
js/graphql-codegen-haskell.js view
@@ -53376,7 +53376,7 @@ }))); }); -var template = "{- This file was automatically generated and should not be edited. -}\n\n{-# LANGUAGE DataKinds #-}\n{-# LANGUAGE DuplicateRecordFields #-}\n{-# LANGUAGE OverloadedStrings #-}\n{-# LANGUAGE QuasiQuotes #-}\n{-# LANGUAGE TypeFamilies #-}\n{-# OPTIONS_GHC -w #-}\n\nmodule {{apiModule}} where\n\nimport Data.GraphQL\nimport Data.GraphQL.Bootstrap\n\nimport {{scalarsModule}}\n{{#enumModules}}\nimport {{.}}\n{{/enumModules}}\n\n{{#operations}}\n{-----------------------------------------------------------------------------\n-- {{name}}\n\n-- result :: Object {{schemaType}}; throws a GraphQL exception on errors\nresult <- runQuery {{queryName}}\n {{#overArgs}}\n { _{{arg}} = ...\n {{/overArgs}}\n }\n\n-- result :: GraphQLResult (Object {{schemaType}})\nresult <- runQuerySafe {{queryName}}\n {{#overArgs}}\n { _{{arg}} = ...\n {{/overArgs}}\n }\n-----------------------------------------------------------------------------}\n\ndata {{queryName}} = {{queryName}}\n {{#overArgs}}\n { _{{arg}} :: {{type}}\n {{/overArgs}}\n }\n deriving (Show)\n\ntype {{schemaType}} = [schema|\n {{schema}}\n|]\n\ninstance GraphQLQuery {{queryName}} where\n type ResultSchema {{queryName}} = {{schemaType}}\n\n getQueryName _ = \"{{name}}\"\n\n getQueryText _ = [query|\n {{queryText}}\n |]\n\n getArgs query = object\n {{#overArgs}}\n [ \"{{arg}}\" .= _{{arg}} (query :: {{queryName}})\n {{/overArgs}}\n ]\n\n{{/operations}}\n";+var template = "{- This file was automatically generated and should not be edited. -}\n\n{-# LANGUAGE DataKinds #-}\n{-# LANGUAGE DuplicateRecordFields #-}\n{-# LANGUAGE OverloadedStrings #-}\n{-# LANGUAGE QuasiQuotes #-}\n{-# LANGUAGE RecordWildCards #-}\n{-# LANGUAGE TypeFamilies #-}\n{-# OPTIONS_GHC -w #-}\n\nmodule {{apiModule}} where\n\nimport Data.GraphQL\nimport Data.GraphQL.Bootstrap\n\nimport {{scalarsModule}}\n{{#enumModules}}\nimport {{.}}\n{{/enumModules}}\n\n{{#operations}}\n{-----------------------------------------------------------------------------\n-- {{name}}\n\n-- result :: Object {{schemaType}}; throws a GraphQL exception on errors\nresult <- runQuery {{queryName}}\n {{#overArgs}}\n { _{{arg}} = ...\n {{/overArgs}}\n }\n\n-- result :: GraphQLResult (Object {{schemaType}})\nresult <- runQuerySafe {{queryName}}\n {{#overArgs}}\n { _{{arg}} = ...\n {{/overArgs}}\n }\n-----------------------------------------------------------------------------}\n\ndata {{queryName}} = {{queryName}}\n {{#overArgs}}\n { _{{arg}} :: {{type}}\n {{/overArgs}}\n }\n deriving (Show)\n\ntype {{schemaType}} = [schema|\n {{schema}}\n|]\n\ninstance GraphQLQuery {{queryName}} where\n type ResultSchema {{queryName}} = {{schemaType}}\n\n getQueryName _ = \"{{name}}\"\n\n getQueryText _ = [query|\n {{queryText}}\n |]\n\n getArgs {{queryName}}{{argsRecordSyntax}} = object\n {{#overArgs}}\n [ \"{{arg}}\" .= _{{arg}}\n {{/overArgs}}\n ]\n\n{{/operations}}\n"; // globally disable html-escaping mustache.escape = function (x) { return x; }; @@ -53392,7 +53392,10 @@ return function (text) { return templateOverList(text, _this.args, { context: _this }); }; - } })); }) })); + }, + // `X{..}` is not valid in GHC < 9.8 if constructor has no fields + // https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0496-empty-record-wildcards.rst + argsRecordSyntax: operation.args.length === 0 ? '{}' : '{..}' })); }) })); }; var renderHaskellType = function (type) { var baseType = type.list
+ test/Data/GraphQL/Test/Generation/TestGeneration.hs view
@@ -0,0 +1,18 @@+module Data.GraphQL.Test.Generation.TestGeneration (testGeneration) where++import System.Exit (ExitCode (..))+import System.Process (readProcessWithExitCode)+import Test.Tasty+import Test.Tasty.HUnit++testGeneration :: TestTree+testGeneration =+ testCase "Test generated code" $ do+ (code, _, _) <- readProcessWithExitCode "bash" ["test/Data/GraphQL/Test/Generation/run.sh", logFile] ""+ case code of+ ExitSuccess -> pure ()+ ExitFailure _ -> do+ output <- readFile logFile+ assertFailure $ "===== Test failed. Output: =====\n" <> output+ where+ logFile = "/tmp/graphql-client-generation-test.log"
+ test/Data/GraphQL/Test/Generation/codegen.yml view
@@ -0,0 +1,7 @@+schema: schema.graphql+documents: queries/*.graphql++hsSourceDir: gen/+apiModule: Example.API+enumsModule: Example.Enums+scalarsModule: Example.Scalars
+ test/Data/GraphQL/Test/Generation/queries/basic.graphql view
@@ -0,0 +1,8 @@+query getUsers {+ users {+ id+ name+ age+ gender+ }+}
+ test/Data/GraphQL/Test/Generation/queries/duplicate-names.graphql view
@@ -0,0 +1,11 @@+query getAge($name: String!) {+ userByName(name: $name) {+ age+ }+}++query getGender($name: String!) {+ userByName(name: $name) {+ gender+ }+}
+ test/Data/GraphQL/Test/Generation/run.sh view
@@ -0,0 +1,24 @@+#!/usr/bin/env bash+#+# Run the test, called in TestGeneration.hs++set -eux -o pipefail++builtin cd "$(dirname "${BASH_SOURCE}")"++LOG_FILE=$1+exec &> "${LOG_FILE}"++graphql-codegen++cat "${GHC_ENVIRONMENT}"++ghc \+ -v \+ --make \+ -odir gen/out/ \+ -hidir gen/out/ \+ -isrc:gen \+ Example.Scalars \+ Example.Enums.Gender \+ Example.API
+ test/Data/GraphQL/Test/Generation/schema.graphql view
@@ -0,0 +1,20 @@+type Query {+ users: [User]+ user(id: ID!): User+ userByName(name: String!): User+}++type User {+ id: ID!+ name: String!+ age: Age+ gender: Gender+}++scalar Age++enum Gender {+ MALE+ FEMALE+ OTHER+}
+ test/Data/GraphQL/Test/Generation/src/Example/Scalars.hs view
@@ -0,0 +1,16 @@+module Example.Scalars where++import Control.Monad (guard)+import Data.Aeson (FromJSON (..), ToJSON (..))++newtype Age = Age Int+ deriving (Show)++instance FromJSON Age where+ parseJSON v = do+ n <- parseJSON v+ guard $ n >= 0+ pure $ Age n++instance ToJSON Age where+ toJSON (Age n) = toJSON n
test/Main.hs view
@@ -1,5 +1,6 @@ import Test.Tasty (defaultMain, testGroup) +import Data.GraphQL.Test.Generation.TestGeneration import Data.GraphQL.Test.Monad.Class import Data.GraphQL.Test.TestUtils @@ -10,4 +11,5 @@ "graphql-client" [ testRunQuery , testTestUtils+ , testGeneration ]