graphql-client 1.1.0 → 1.1.1
raw patch · 6 files changed
+55/−17 lines, 6 filesdep ~aesondep ~aeson-schemasdep ~bytestringPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: aeson, aeson-schemas, bytestring, file-embed, optparse-applicative, path, path-io, typed-process
API changes (from Hackage documentation)
Files
- CHANGELOG.md +6/−0
- exe/Codegen.hs +15/−2
- graphql-client.cabal +3/−3
- js/graphql-codegen-haskell.js +31/−10
- src/Data/GraphQL/Query.hs +0/−1
- src/Data/GraphQL/Result.hs +0/−1
CHANGELOG.md view
@@ -1,5 +1,11 @@ ## Upcoming +## 1.1.1++Bug fixes:++* Generate enums that only appear in query arguments ([#59](https://github.com/LeapYear/graphql-client/pull/59))+ ## 1.1.0 Breaking changes:
exe/Codegen.hs view
@@ -1,8 +1,12 @@+{-# LANGUAGE LambdaCase #-}+{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE RecordWildCards #-} {-# LANGUAGE TemplateHaskell #-}+{-# LANGUAGE TypeApplications #-} -import Control.Monad (forM_)+import Control.Exception (SomeException, try)+import Control.Monad (forM_, unless) import Data.ByteString (ByteString) import qualified Data.ByteString as ByteString import Data.FileEmbed (bsToExp, embedFile, getDir)@@ -11,7 +15,8 @@ import Options.Applicative import Path import Path.IO (doesFileExist, ensureDir, resolveFile', withSystemTempDir)-import System.Process.Typed (proc, runProcess_)+import System.Exit (ExitCode(..))+import System.Process.Typed (proc, readProcess, runProcess_) data CliOptions = CliOptions { cliNode :: Maybe FilePath@@ -72,6 +77,14 @@ nodeExe <- maybe (pure "node") (fmap toFilePath . resolveFile') cliNode configFile <- resolveFile' cliConfig++ configFileExists <- doesFileExist configFile+ unless configFileExists $+ errorWithoutStackTrace $ "Config file doesn't exist: " ++ toFilePath configFile++ try @SomeException (readProcess $ proc nodeExe ["-e", "console.log('TEST')"]) >>= \case+ Right (ExitSuccess, "TEST\n", _) -> return ()+ _ -> errorWithoutStackTrace $ "Could not find working Node executable: " ++ nodeExe runProcess_ $ proc nodeExe [toFilePath graphqlCodegen, toFilePath configFile] where
graphql-client.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: 1e5cbd0fa96a9b044b801baafda6953cf3b51d16e5030235bd6bad5d908f07af+-- hash: c25accf7e3c21d0afe69d04182d67865d8683906b4a860ad622fb99dcfcaa63d name: graphql-client-version: 1.1.0+version: 1.1.1 synopsis: A client for Haskell programs to query a GraphQL API description: A client for Haskell programs to query a GraphQL API. category: Graphql@@ -79,7 +79,7 @@ , http-client-tls >=0.3.5.3 && <0.4 , http-types >=0.12.1 && <0.13 , mtl >=2.2.2 && <2.3- , optparse-applicative >=0.14.2.0 && <0.15.2+ , optparse-applicative >=0.14.2.0 && <0.16.2 , path >=0.6.1 && <0.8.0 , path-io >=1.3.3 && <1.7.0 , template-haskell >=2.12.0.0 && <3
js/graphql-codegen-haskell.js view
@@ -52502,14 +52502,23 @@ return SelectionSetParser; }()); -var parseVariableDefinitions = function (variableDefinitions) { - return variableDefinitions.map(function (_a) { +var parseVariableDefinitions = function (schema, variableDefinitions) { + var args = variableDefinitions.map(function (_a) { var type = _a.type, variable = _a.variable; return ({ name: variable.name.value, type: parseType$1(type), }); }); + var enums = new Set(); + args.forEach(function (_a) { + var type = _a.type; + var enumName = getEnumName(schema, type); + if (enumName) { + enums.add(enumName); + } + }); + return { args: args, enums: enums }; }; var parseType$1 = function (type, nullable) { if (nullable === void 0) { nullable = true; } @@ -52521,6 +52530,13 @@ case Kind.NON_NULL_TYPE: return parseType$1(type.type, false); } +}; +var getEnumName = function (schema, type) { + if (type.list) { + return getEnumName(schema, type.inner); + } + var schemaType = schema.getType(type.name); + return isEnumType(schemaType) ? type.name : null; }; var parseOperations = function (ast, schema, fragments) { @@ -52562,7 +52578,8 @@ var name = (_b = (_a = node.name) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : "unnamed" + this._unnamedCounter++; var capitalName = capitalize$1(name); var opType = capitalize$1(node.operation); - var args = parseVariableDefinitions((_c = node.variableDefinitions) !== null && _c !== void 0 ? _c : []); + var variableDefinitions = parseVariableDefinitions(this.schema, (_c = node.variableDefinitions) !== null && _c !== void 0 ? _c : []); + this.addEnums(variableDefinitions.enums); var schemaRoot; switch (node.operation) { case 'query': @@ -52578,22 +52595,26 @@ if (!schemaRoot) { throw new Error("Unable to find root schema type for operation type \"" + node.operation + "\""); } - var _d = parseSelectionSet(this.schema, node.selectionSet, schemaRoot, this.fragments), enums = _d.enums, fragments = _d.fragments, selections = _d.selections; - enums.forEach(function (e) { - _this._enums.add(e); - }); + var selectionSet = parseSelectionSet(this.schema, node.selectionSet, schemaRoot, this.fragments); + this.addEnums(selectionSet.enums); return { name: name, queryText: __spreadArrays([ print(node) - ], fragments.map(function (fragment) { + ], selectionSet.fragments.map(function (fragment) { return print(_this.fragments[fragment]); })).join('\n'), queryName: "" + capitalName + opType, - args: args, + args: variableDefinitions.args, schemaType: capitalName + "Schema", - schema: selections, + schema: selectionSet.selections, }; + }; + OperationDefinitionParser.prototype.addEnums = function (enums) { + var _this = this; + enums.forEach(function (e) { + _this._enums.add(e); + }); }; return OperationDefinitionParser; }());
src/Data/GraphQL/Query.hs view
@@ -6,7 +6,6 @@ Definitions needed by GraphQL queries. -}-{-# LANGUAGE DataKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TypeFamilies #-}
src/Data/GraphQL/Result.hs view
@@ -6,7 +6,6 @@ Definitions parsing responses from a GraphQL API. -}-{-# LANGUAGE DeriveFunctor #-} {-# LANGUAGE DeriveTraversable #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE OverloadedStrings #-}