Skip to content

Commit

Permalink
Add defineBy*File' variant that takes a Q FilePath
Browse files Browse the repository at this point in the history
This enables using utilities such as
https://hackage.haskell.org/package/file-embed-0.0.13.0/docs/Data-FileEmbed.html#v:makeRelativeToProject
which can be used to work around file path issues when using multi
package projects.
  • Loading branch information
AlistairB committed Mar 28, 2021
1 parent f76f54e commit a7d73f2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions morpheus-graphql-client/changelog.md
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Minor Changes

- Add defineBy*File' variants that take a `Q FilePath` [#584](https://github.com/morpheusgraphql/morpheus-graphql/pull/584)

## 0.17.0 - 25.02.2021

### Breaking changes
Expand Down
10 changes: 10 additions & 0 deletions morpheus-graphql-client/src/Data/Morpheus/Client.hs
Expand Up @@ -7,8 +7,10 @@ module Data.Morpheus.Client
defineQuery,
defineByDocument,
defineByDocumentFile,
defineByDocumentFile',
defineByIntrospection,
defineByIntrospectionFile,
defineByIntrospectionFile',
ScalarValue (..),
DecodeScalar (..),
EncodeScalar (..),
Expand Down Expand Up @@ -58,11 +60,19 @@ defineByDocumentFile filePath args = do
qAddDependentFile filePath
defineByDocument (L.readFile filePath) args

-- | This variant exposes 'Q FilePath' enabling the use of TH to generate the 'FilePath'. For example, https://hackage.haskell.org/package/file-embed-0.0.13.0/docs/Data-FileEmbed.html#v:makeRelativeToProject can be used to handle multi package projects more reliably.
defineByDocumentFile' :: Q FilePath -> (ExecutableDocument, String) -> Q [Dec]
defineByDocumentFile' qFilePath args = qFilePath >>= flip defineByDocumentFile args

defineByIntrospectionFile :: FilePath -> (ExecutableDocument, String) -> Q [Dec]
defineByIntrospectionFile filePath args = do
qAddDependentFile filePath
defineByIntrospection (L.readFile filePath) args

-- | This variant exposes 'Q FilePath' enabling the use of TH to generate the 'FilePath'. For example, https://hackage.haskell.org/package/file-embed-0.0.13.0/docs/Data-FileEmbed.html#v:makeRelativeToProject can be used to handle multi package projects more reliably.
defineByIntrospectionFile' :: Q FilePath -> (ExecutableDocument, String) -> Q [Dec]
defineByIntrospectionFile' qFilePath args = qFilePath >>= flip defineByIntrospectionFile args

defineByDocument :: IO ByteString -> (ExecutableDocument, String) -> Q [Dec]
defineByDocument doc = defineQuery (schemaByDocument doc)

Expand Down

0 comments on commit a7d73f2

Please sign in to comment.