From 01854dcba110141e178e87bccbfa58ceb6383e4d Mon Sep 17 00:00:00 2001 From: Bakhtiyar Neyman Date: Tue, 30 Apr 2024 15:52:26 -0700 Subject: [PATCH 1/6] Derive a few GqlUnion and UnionReturned instances in GraphQL/Client/Union.purs --- src/GraphQL/Client/Union.purs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/GraphQL/Client/Union.purs b/src/GraphQL/Client/Union.purs index 594f83e..3332abf 100644 --- a/src/GraphQL/Client/Union.purs +++ b/src/GraphQL/Client/Union.purs @@ -18,11 +18,13 @@ import Type.Proxy (Proxy(..)) newtype GqlUnion r = GqlUnion (Record r) -derive instance newtypeGqlUnion :: Newtype (GqlUnion r) _ +derive newtype instance Eq (Record r) => Eq (GqlUnion r) +derive newtype instance Ord (Record r) => Ord (GqlUnion r) +derive instance Newtype (GqlUnion r) _ newtype UnionReturned r = UnionReturned (Variant r) -derive instance newtypeGqlUnionReturned :: Newtype (UnionReturned r) _ +derive instance Newtype (UnionReturned r) _ instance (RL.RowToList r rl, DecodeUnion rl r) => DecodeJson (UnionReturned r) where decodeJson = decodeJsonUnionWith (decodeUnion :: _ -> _ -> Proxy rl -> _) @@ -104,4 +106,3 @@ failedAtTypename ty _ _ = Left $ AtKey __typename $ UnexpectedValue $ fromString __typename :: String __typename = "__typename" - From a5531b0dc1393b0d0f984cf8a8d92333b4705956 Mon Sep 17 00:00:00 2001 From: Bakhtiyar Neyman Date: Tue, 30 Apr 2024 16:20:41 -0700 Subject: [PATCH 2/6] Replace the port 4000 with an unassigned port 4892. 4000 can often lead to clashes with other processes. --- README.md | 14 ++++++-------- e2e/1-affjax/server-fn.js | 6 +++--- e2e/1-affjax/server.js | 2 +- e2e/1-affjax/src/Main.purs | 2 +- e2e/2-comments/generate-purs-schema.mjs | 2 +- e2e/2-comments/server-fn.js | 2 +- e2e/2-comments/server.js | 2 +- e2e/2-comments/src/Main.purs | 2 +- examples/1-simple/server-fn.js | 6 +++--- examples/1-simple/server.js | 2 +- examples/1-simple/src/Main.purs | 2 +- examples/10-aliases/server-fn.js | 6 +++--- examples/10-aliases/server.js | 2 +- examples/10-aliases/src/Main.purs | 2 +- examples/11-unions/generate-purs-schema.mjs | 2 +- examples/11-unions/server-fn.js | 4 ++-- examples/11-unions/server.js | 2 +- examples/11-unions/spago.dhall | 2 +- examples/11-unions/src/Main.purs | 4 ++-- examples/12-directives/generate-purs-schema.mjs | 2 +- examples/12-directives/server-fn.js | 8 ++++---- examples/12-directives/server.js | 2 +- examples/12-directives/src/Main.purs | 2 +- examples/13-error-boundaries/server-fn.js | 6 +++--- examples/13-error-boundaries/server.js | 2 +- examples/13-error-boundaries/src/Main.purs | 2 +- examples/2-codegen/generate-purs-schema.js | 2 +- examples/2-codegen/generate-purs-schema.mjs | 2 +- examples/2-codegen/server-fn.js | 6 +++--- examples/2-codegen/server.js | 2 +- examples/2-codegen/src/Main.purs | 2 +- examples/3-enums/generate-purs-schema.mjs | 2 +- examples/3-enums/server-fn.js | 2 +- examples/3-enums/server.js | 2 +- examples/3-enums/src/Main.purs | 4 ++-- examples/4-mutation/generate-purs-schema.mjs | 2 +- examples/4-mutation/server-fn.js | 6 +++--- examples/4-mutation/server.js | 2 +- examples/4-mutation/src/Main.purs | 3 +-- examples/5-subscription/generate-purs-schema.mjs | 2 +- examples/5-subscription/server-fn.js | 4 ++-- examples/5-subscription/src/Main.purs | 4 ++-- examples/6-watch-query/generate-purs-schema.mjs | 2 +- examples/6-watch-query/server-fn.js | 4 ++-- examples/6-watch-query/src/Main.purs | 11 +++++------ .../generate-purs-schema.mjs | 2 +- examples/7-field-type-overrides/server-fn.js | 6 +++--- examples/7-field-type-overrides/server.js | 2 +- examples/7-field-type-overrides/src/Main.purs | 2 +- .../8-custom-gql-types/generate-purs-schema.mjs | 2 +- examples/8-custom-gql-types/server-fn.js | 6 +++--- examples/8-custom-gql-types/server.js | 2 +- examples/8-custom-gql-types/src/Main.purs | 2 +- examples/9-variables/generate-purs-schema.mjs | 2 +- examples/9-variables/server-fn.js | 2 +- examples/9-variables/server.js | 2 +- examples/9-variables/src/Main.purs | 2 +- 57 files changed, 91 insertions(+), 95 deletions(-) diff --git a/README.md b/README.md index 650051c..54e28b3 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ queryGql :: GqlQuery Nil' OpQuery Schema query returns => DecodeJson returns => String -> query -> Aff returns -queryGql = query_ "http://localhost:4000/graphql" (Proxy :: Proxy Schema) +queryGql = query_ "http://localhost:4892/graphql" (Proxy :: Proxy Schema) -- Schema type Schema @@ -129,7 +129,7 @@ const { generateSchema } = require('purescript-graphql-client') generateSchema({ dir: './src/generated', // Where you want the generated code to go modulePath: ['Generated', 'Gql'], // The name of the generated module - url: 'http://localhost:4000/graphql' // Your graphql enppdint + url: 'http://localhost:4892/graphql' // Your graphql enppdint }) ``` @@ -148,7 +148,7 @@ generateSchemas({ modulePath: ['Generated', 'Gql'] }, [ { - url: 'http://localhost:4000/graphql', + url: 'http://localhost:4892/graphql', moduleName: 'MySchema' // The name of the module for this single schema } ]) @@ -187,7 +187,7 @@ import Type.Data.List (Nil') ... client :: Client _ Nil' Query Mutation Void <- createClient - { url: "http://localhost:4000/graphql" + { url: "http://localhost:4892/graphql" , authToken: Nothing , headers: [] } @@ -217,10 +217,10 @@ import Type.Data.List (Nil') client :: Client _ Nil' Query Mutation Subscription <- createSubscriptionClient - { url: "http://localhost:4000/graphql" + { url: "http://localhost:4892/graphql" , authToken: Nothing , headers: [] - , websocketUrl: "ws://localhost:4000/subscriptions" + , websocketUrl: "ws://localhost:4892/subscriptions" } let event = subscription client "get_props" @@ -478,5 +478,3 @@ Although the names and scope of the 2 packages are very similar they are not con - This package uses record syntax to make queries whereas purescript-graphqlclient uses applicative/ado syntax - This package allows use of Apollo if you wish (or other lower level graphQL clients) - This package supports subscriptions, watch queries and client caching - - diff --git a/e2e/1-affjax/server-fn.js b/e2e/1-affjax/server-fn.js index 6e179cd..2b84c97 100644 --- a/e2e/1-affjax/server-fn.js +++ b/e2e/1-affjax/server-fn.js @@ -9,8 +9,8 @@ module.exports = (onListening) => { prop: String widgets(id: Int): [Widget!]! } - - type Widget { + + type Widget { id: Int name: String! } @@ -38,5 +38,5 @@ module.exports = (onListening) => { graphiql: true })) - app.listen(4000, onListening) + app.listen(4892, onListening) } diff --git a/e2e/1-affjax/server.js b/e2e/1-affjax/server.js index b8065c5..333a475 100644 --- a/e2e/1-affjax/server.js +++ b/e2e/1-affjax/server.js @@ -1,4 +1,4 @@ import serverFn from './server-fn.js' serverFn(() => { - console.info('Running a GraphQL API server at http://localhost:4000/graphql') + console.info('Running a GraphQL API server at http://localhost:4892/graphql') }) diff --git a/e2e/1-affjax/src/Main.purs b/e2e/1-affjax/src/Main.purs index 9a0d331..770424b 100644 --- a/e2e/1-affjax/src/Main.purs +++ b/e2e/1-affjax/src/Main.purs @@ -47,7 +47,7 @@ client , mutation :: Void , subscription :: Void } -client = (Client $ AffjaxNodeClient "http://localhost:4000/graphql" []) +client = (Client $ AffjaxNodeClient "http://localhost:4892/graphql" []) -- Schema type Schema = diff --git a/e2e/2-comments/generate-purs-schema.mjs b/e2e/2-comments/generate-purs-schema.mjs index efbaf2d..c1303d2 100644 --- a/e2e/2-comments/generate-purs-schema.mjs +++ b/e2e/2-comments/generate-purs-schema.mjs @@ -9,7 +9,7 @@ export default () => useNewtypesForRecords: true }, [ { - url: 'http://localhost:4000/graphql', + url: 'http://localhost:4892/graphql', moduleName: 'Admin' } ]) diff --git a/e2e/2-comments/server-fn.js b/e2e/2-comments/server-fn.js index 1c95667..f9c7bfc 100644 --- a/e2e/2-comments/server-fn.js +++ b/e2e/2-comments/server-fn.js @@ -46,5 +46,5 @@ module.exports = (onListening) => { graphiql: true })) - app.listen(4000, onListening) + app.listen(4892, onListening) } diff --git a/e2e/2-comments/server.js b/e2e/2-comments/server.js index b8065c5..333a475 100644 --- a/e2e/2-comments/server.js +++ b/e2e/2-comments/server.js @@ -1,4 +1,4 @@ import serverFn from './server-fn.js' serverFn(() => { - console.info('Running a GraphQL API server at http://localhost:4000/graphql') + console.info('Running a GraphQL API server at http://localhost:4892/graphql') }) diff --git a/e2e/2-comments/src/Main.purs b/e2e/2-comments/src/Main.purs index 667d944..17511e8 100644 --- a/e2e/2-comments/src/Main.purs +++ b/e2e/2-comments/src/Main.purs @@ -34,4 +34,4 @@ queryGql :: GqlQuery Nil' OpQuery Query query returns => DecodeJson returns => String -> query -> Aff returns -queryGql = query_ "http://localhost:4000/graphql" (Proxy :: Proxy Query) +queryGql = query_ "http://localhost:4892/graphql" (Proxy :: Proxy Query) diff --git a/examples/1-simple/server-fn.js b/examples/1-simple/server-fn.js index 6e179cd..2b84c97 100644 --- a/examples/1-simple/server-fn.js +++ b/examples/1-simple/server-fn.js @@ -9,8 +9,8 @@ module.exports = (onListening) => { prop: String widgets(id: Int): [Widget!]! } - - type Widget { + + type Widget { id: Int name: String! } @@ -38,5 +38,5 @@ module.exports = (onListening) => { graphiql: true })) - app.listen(4000, onListening) + app.listen(4892, onListening) } diff --git a/examples/1-simple/server.js b/examples/1-simple/server.js index b8065c5..333a475 100644 --- a/examples/1-simple/server.js +++ b/examples/1-simple/server.js @@ -1,4 +1,4 @@ import serverFn from './server-fn.js' serverFn(() => { - console.info('Running a GraphQL API server at http://localhost:4000/graphql') + console.info('Running a GraphQL API server at http://localhost:4892/graphql') }) diff --git a/examples/1-simple/src/Main.purs b/examples/1-simple/src/Main.purs index e9eae2c..dc59219 100644 --- a/examples/1-simple/src/Main.purs +++ b/examples/1-simple/src/Main.purs @@ -27,7 +27,7 @@ queryGql :: GqlQuery Nil' OpQuery Schema query returns => DecodeJson returns => String -> query -> Aff returns -queryGql = query_ "http://localhost:4000/graphql" (Proxy :: Proxy Schema) +queryGql = query_ "http://localhost:4892/graphql" (Proxy :: Proxy Schema) -- Schema type Schema diff --git a/examples/10-aliases/server-fn.js b/examples/10-aliases/server-fn.js index 6e179cd..2b84c97 100644 --- a/examples/10-aliases/server-fn.js +++ b/examples/10-aliases/server-fn.js @@ -9,8 +9,8 @@ module.exports = (onListening) => { prop: String widgets(id: Int): [Widget!]! } - - type Widget { + + type Widget { id: Int name: String! } @@ -38,5 +38,5 @@ module.exports = (onListening) => { graphiql: true })) - app.listen(4000, onListening) + app.listen(4892, onListening) } diff --git a/examples/10-aliases/server.js b/examples/10-aliases/server.js index b8065c5..333a475 100644 --- a/examples/10-aliases/server.js +++ b/examples/10-aliases/server.js @@ -1,4 +1,4 @@ import serverFn from './server-fn.js' serverFn(() => { - console.info('Running a GraphQL API server at http://localhost:4000/graphql') + console.info('Running a GraphQL API server at http://localhost:4892/graphql') }) diff --git a/examples/10-aliases/src/Main.purs b/examples/10-aliases/src/Main.purs index efbef04..5b6f35a 100644 --- a/examples/10-aliases/src/Main.purs +++ b/examples/10-aliases/src/Main.purs @@ -39,7 +39,7 @@ queryGql :: GqlQuery Nil' OpQuery Schema query returns => DecodeJson returns => String -> query -> Aff returns -queryGql = query_ "http://localhost:4000/graphql" (Proxy :: Proxy Schema) +queryGql = query_ "http://localhost:4892/graphql" (Proxy :: Proxy Schema) -- Schema type Schema diff --git a/examples/11-unions/generate-purs-schema.mjs b/examples/11-unions/generate-purs-schema.mjs index ed9aa2a..3c755b9 100644 --- a/examples/11-unions/generate-purs-schema.mjs +++ b/examples/11-unions/generate-purs-schema.mjs @@ -9,7 +9,7 @@ export default () => useNewtypesForRecords: false }, [ { - url: 'http://localhost:4000/graphql', + url: 'http://localhost:4892/graphql', moduleName: 'Admin' } ]) diff --git a/examples/11-unions/server-fn.js b/examples/11-unions/server-fn.js index 0809847..4ef8d41 100644 --- a/examples/11-unions/server-fn.js +++ b/examples/11-unions/server-fn.js @@ -32,7 +32,7 @@ module.exports = (onListening) => { height: 1.8, id: 1, }; - }else { + }else { return { __typename: "Droid", name: "R2D2", @@ -54,5 +54,5 @@ module.exports = (onListening) => { }) ); - app.listen(4000, onListening); + app.listen(4892, onListening); }; diff --git a/examples/11-unions/server.js b/examples/11-unions/server.js index 8b2fcfb..4cc61b8 100644 --- a/examples/11-unions/server.js +++ b/examples/11-unions/server.js @@ -1,3 +1,3 @@ require('./server-fn')(() => { - console.info('Running a GraphQL API server at http://localhost:4000/graphql') + console.info('Running a GraphQL API server at http://localhost:4892/graphql') }) diff --git a/examples/11-unions/spago.dhall b/examples/11-unions/spago.dhall index 606c488..3637627 100644 --- a/examples/11-unions/spago.dhall +++ b/examples/11-unions/spago.dhall @@ -5,5 +5,5 @@ You can edit this file as you like. { name = "my-project" , dependencies = ../../test-deps.dhall , packages = ./packages.dhall -, sources = [ "src/**/*.purs", "test/**/*.purs", "../../src/**/*.purs" ] +, sources = [ "src/**/*.purs", "../../src/**/*.purs" ] } diff --git a/examples/11-unions/src/Main.purs b/examples/11-unions/src/Main.purs index 461a66f..406a5e2 100644 --- a/examples/11-unions/src/Main.purs +++ b/examples/11-unions/src/Main.purs @@ -9,8 +9,8 @@ import Effect.Aff (Aff, launchAff_) import Effect.Class.Console (logShow) import Generated.Gql.Schema.Admin (Query) import GraphQL.Client.Args ((=>>)) -import GraphQL.Client.Query (query_) import GraphQL.Client.Operation (OpQuery) +import GraphQL.Client.Query (query_) import GraphQL.Client.Types (class GqlQuery) import GraphQL.Client.Union (GqlUnion(..)) import Type.Data.List (Nil') @@ -39,4 +39,4 @@ queryGql => String -> query -> Aff returns -queryGql = query_ "http://localhost:4000/graphql" (Proxy :: Proxy Query) +queryGql = query_ "http://localhost:4892/graphql" (Proxy :: Proxy Query) diff --git a/examples/12-directives/generate-purs-schema.mjs b/examples/12-directives/generate-purs-schema.mjs index ed9aa2a..3c755b9 100644 --- a/examples/12-directives/generate-purs-schema.mjs +++ b/examples/12-directives/generate-purs-schema.mjs @@ -9,7 +9,7 @@ export default () => useNewtypesForRecords: false }, [ { - url: 'http://localhost:4000/graphql', + url: 'http://localhost:4892/graphql', moduleName: 'Admin' } ]) diff --git a/examples/12-directives/server-fn.js b/examples/12-directives/server-fn.js index af7b2c5..2acce96 100644 --- a/examples/12-directives/server-fn.js +++ b/examples/12-directives/server-fn.js @@ -9,7 +9,7 @@ module.exports = (onListening) => { directive @cached( """measured in seconds""" ttl: Int = 60 - + """refresh the cache entry""" refresh: Boolean = false ) on QUERY @@ -18,8 +18,8 @@ module.exports = (onListening) => { prop: String widgets(id: Int): [Widget!]! } - - type Widget { + + type Widget { id: Int name: String! } @@ -47,5 +47,5 @@ module.exports = (onListening) => { graphiql: true })) - app.listen(4000, onListening) + app.listen(4892, onListening) } diff --git a/examples/12-directives/server.js b/examples/12-directives/server.js index 8b2fcfb..4cc61b8 100644 --- a/examples/12-directives/server.js +++ b/examples/12-directives/server.js @@ -1,3 +1,3 @@ require('./server-fn')(() => { - console.info('Running a GraphQL API server at http://localhost:4000/graphql') + console.info('Running a GraphQL API server at http://localhost:4892/graphql') }) diff --git a/examples/12-directives/src/Main.purs b/examples/12-directives/src/Main.purs index 85e4b9c..edbb772 100644 --- a/examples/12-directives/src/Main.purs +++ b/examples/12-directives/src/Main.purs @@ -29,4 +29,4 @@ queryGql :: GqlQuery Directives OpQuery Query query returns => DecodeJson returns => String -> query -> Aff returns -queryGql = query_ "http://localhost:4000/graphql" (Proxy :: Proxy Query) +queryGql = query_ "http://localhost:4892/graphql" (Proxy :: Proxy Query) diff --git a/examples/13-error-boundaries/server-fn.js b/examples/13-error-boundaries/server-fn.js index 32a42cd..10b4a6a 100644 --- a/examples/13-error-boundaries/server-fn.js +++ b/examples/13-error-boundaries/server-fn.js @@ -8,8 +8,8 @@ module.exports = (onListening) => { prop: String widgets(id: Int): [Widget!]! } - - type Widget { + + type Widget { id: Int name: String! contains_bad_type: BadType @@ -51,5 +51,5 @@ module.exports = (onListening) => { }) ); - app.listen(4000, onListening); + app.listen(4892, onListening); }; diff --git a/examples/13-error-boundaries/server.js b/examples/13-error-boundaries/server.js index b8065c5..333a475 100644 --- a/examples/13-error-boundaries/server.js +++ b/examples/13-error-boundaries/server.js @@ -1,4 +1,4 @@ import serverFn from './server-fn.js' serverFn(() => { - console.info('Running a GraphQL API server at http://localhost:4000/graphql') + console.info('Running a GraphQL API server at http://localhost:4892/graphql') }) diff --git a/examples/13-error-boundaries/src/Main.purs b/examples/13-error-boundaries/src/Main.purs index 0b311ff..ae564ab 100644 --- a/examples/13-error-boundaries/src/Main.purs +++ b/examples/13-error-boundaries/src/Main.purs @@ -57,7 +57,7 @@ queryGql name_ q = do client <- liftEffect $ createClient - { url: "http://localhost:4000/graphql" + { url: "http://localhost:4892/graphql" , headers: [] } queryFullRes decodeJson identity (client :: Client UrqlClient { directives :: Proxy Nil', query :: Schema | _ }) name_ q diff --git a/examples/2-codegen/generate-purs-schema.js b/examples/2-codegen/generate-purs-schema.js index bcfeb87..3f53fdd 100644 --- a/examples/2-codegen/generate-purs-schema.js +++ b/examples/2-codegen/generate-purs-schema.js @@ -7,5 +7,5 @@ export default () => dir: './src/generated', modulePath: ['Generated', 'Gql', 'Admin'], useNewtypesForRecords: false, - url: 'http://localhost:4000/graphql' + url: 'http://localhost:4892/graphql' }) diff --git a/examples/2-codegen/generate-purs-schema.mjs b/examples/2-codegen/generate-purs-schema.mjs index bcfeb87..3f53fdd 100644 --- a/examples/2-codegen/generate-purs-schema.mjs +++ b/examples/2-codegen/generate-purs-schema.mjs @@ -7,5 +7,5 @@ export default () => dir: './src/generated', modulePath: ['Generated', 'Gql', 'Admin'], useNewtypesForRecords: false, - url: 'http://localhost:4000/graphql' + url: 'http://localhost:4892/graphql' }) diff --git a/examples/2-codegen/server-fn.js b/examples/2-codegen/server-fn.js index 23ea6c1..ea6b36a 100644 --- a/examples/2-codegen/server-fn.js +++ b/examples/2-codegen/server-fn.js @@ -9,8 +9,8 @@ module.exports = (onListening) => { prop: String widgets(id: ID): [Widget!]! } - - type Widget { + + type Widget { id: ID int: Int name: String! @@ -39,5 +39,5 @@ module.exports = (onListening) => { graphiql: true })) - app.listen(4000, onListening) + app.listen(4892, onListening) } diff --git a/examples/2-codegen/server.js b/examples/2-codegen/server.js index b8065c5..333a475 100644 --- a/examples/2-codegen/server.js +++ b/examples/2-codegen/server.js @@ -1,4 +1,4 @@ import serverFn from './server-fn.js' serverFn(() => { - console.info('Running a GraphQL API server at http://localhost:4000/graphql') + console.info('Running a GraphQL API server at http://localhost:4892/graphql') }) diff --git a/examples/2-codegen/src/Main.purs b/examples/2-codegen/src/Main.purs index fcd1c57..4a977d2 100644 --- a/examples/2-codegen/src/Main.purs +++ b/examples/2-codegen/src/Main.purs @@ -30,4 +30,4 @@ queryGql :: GqlQuery Nil' OpQuery Query query returns => DecodeJson returns => String -> query -> Aff returns -queryGql = query_ "http://localhost:4000/graphql" (Proxy :: Proxy Query) +queryGql = query_ "http://localhost:4892/graphql" (Proxy :: Proxy Query) diff --git a/examples/3-enums/generate-purs-schema.mjs b/examples/3-enums/generate-purs-schema.mjs index ed9aa2a..3c755b9 100644 --- a/examples/3-enums/generate-purs-schema.mjs +++ b/examples/3-enums/generate-purs-schema.mjs @@ -9,7 +9,7 @@ export default () => useNewtypesForRecords: false }, [ { - url: 'http://localhost:4000/graphql', + url: 'http://localhost:4892/graphql', moduleName: 'Admin' } ]) diff --git a/examples/3-enums/server-fn.js b/examples/3-enums/server-fn.js index d471e74..5e8882d 100644 --- a/examples/3-enums/server-fn.js +++ b/examples/3-enums/server-fn.js @@ -47,5 +47,5 @@ module.exports = (onListening) => { graphiql: true })) - app.listen(4000, onListening) + app.listen(4892, onListening) } diff --git a/examples/3-enums/server.js b/examples/3-enums/server.js index b8065c5..333a475 100644 --- a/examples/3-enums/server.js +++ b/examples/3-enums/server.js @@ -1,4 +1,4 @@ import serverFn from './server-fn.js' serverFn(() => { - console.info('Running a GraphQL API server at http://localhost:4000/graphql') + console.info('Running a GraphQL API server at http://localhost:4892/graphql') }) diff --git a/examples/3-enums/src/Main.purs b/examples/3-enums/src/Main.purs index 8fcd64e..434be48 100644 --- a/examples/3-enums/src/Main.purs +++ b/examples/3-enums/src/Main.purs @@ -22,7 +22,7 @@ main = { widgets } <- queryGql "WidgetColoursWithId1" { widgets: { colour: RED } =>> { colour } } - + -- Will log [ RED ] as there is one red widget logShow $ map _.colour widgets @@ -32,4 +32,4 @@ queryGql :: GqlQuery Nil' OpQuery Query query returns => DecodeJson returns => String -> query -> Aff returns -queryGql = query_ "http://localhost:4000/graphql" (Proxy :: Proxy Query) +queryGql = query_ "http://localhost:4892/graphql" (Proxy :: Proxy Query) diff --git a/examples/4-mutation/generate-purs-schema.mjs b/examples/4-mutation/generate-purs-schema.mjs index ed9aa2a..3c755b9 100644 --- a/examples/4-mutation/generate-purs-schema.mjs +++ b/examples/4-mutation/generate-purs-schema.mjs @@ -9,7 +9,7 @@ export default () => useNewtypesForRecords: false }, [ { - url: 'http://localhost:4000/graphql', + url: 'http://localhost:4892/graphql', moduleName: 'Admin' } ]) diff --git a/examples/4-mutation/server-fn.js b/examples/4-mutation/server-fn.js index c212b09..62dd7b3 100644 --- a/examples/4-mutation/server-fn.js +++ b/examples/4-mutation/server-fn.js @@ -4,7 +4,7 @@ const widgets = [ { id: 2, name: 'two', colour: 'GREEN' } ] -module.exports = (onListening) => { +module.exports = (onListening) => { const express = require('express') const { graphqlHTTP } = require('express-graphql') const { buildSchema } = require('graphql') @@ -28,7 +28,7 @@ module.exports = (onListening) => { yellow } - type Mutation { + type Mutation { set_widget_colour(id: Int!, colour: Colour!): Int! } @@ -58,5 +58,5 @@ module.exports = (onListening) => { graphiql: true })) - app.listen(4000, onListening) + app.listen(4892, onListening) } diff --git a/examples/4-mutation/server.js b/examples/4-mutation/server.js index b8065c5..333a475 100644 --- a/examples/4-mutation/server.js +++ b/examples/4-mutation/server.js @@ -1,4 +1,4 @@ import serverFn from './server-fn.js' serverFn(() => { - console.info('Running a GraphQL API server at http://localhost:4000/graphql') + console.info('Running a GraphQL API server at http://localhost:4892/graphql') }) diff --git a/examples/4-mutation/src/Main.purs b/examples/4-mutation/src/Main.purs index 75c53ea..a8bdd82 100644 --- a/examples/4-mutation/src/Main.purs +++ b/examples/4-mutation/src/Main.purs @@ -20,7 +20,7 @@ main :: Effect Unit main = do client :: Client _ Schema <- createClient - { url: "http://localhost:4000/graphql" + { url: "http://localhost:4892/graphql" , authToken: Nothing , headers: [] } @@ -59,4 +59,3 @@ main = do -- Will also log [ GREEN ] logShow $ map _.colour updatedWidgetsWithoutCache - diff --git a/examples/5-subscription/generate-purs-schema.mjs b/examples/5-subscription/generate-purs-schema.mjs index ed9aa2a..3c755b9 100644 --- a/examples/5-subscription/generate-purs-schema.mjs +++ b/examples/5-subscription/generate-purs-schema.mjs @@ -9,7 +9,7 @@ export default () => useNewtypesForRecords: false }, [ { - url: 'http://localhost:4000/graphql', + url: 'http://localhost:4892/graphql', moduleName: 'Admin' } ]) diff --git a/examples/5-subscription/server-fn.js b/examples/5-subscription/server-fn.js index 43c1909..02afa6a 100644 --- a/examples/5-subscription/server-fn.js +++ b/examples/5-subscription/server-fn.js @@ -28,7 +28,7 @@ module.exports = async (onListening) => { comment: String! } `) - const PORT = 4000 + const PORT = 4892 const app = express() app.use('/graphql', bodyParser.json()) @@ -75,7 +75,7 @@ module.exports = async (onListening) => { plugins: [ // Proper shutdown for the HTTP server. ApolloServerPluginDrainHttpServer({ httpServer }), - + // Proper shutdown for the WebSocket server. { async serverWillStart() { diff --git a/examples/5-subscription/src/Main.purs b/examples/5-subscription/src/Main.purs index 2a8510d..078417b 100644 --- a/examples/5-subscription/src/Main.purs +++ b/examples/5-subscription/src/Main.purs @@ -18,10 +18,10 @@ main :: Effect Unit main = do client :: Client _ Schema <- createSubscriptionClient - { url: "http://localhost:4000/graphql" + { url: "http://localhost:4892/graphql" , authToken: Nothing , headers: [] - , websocketUrl: "ws://localhost:4000/graphql" + , websocketUrl: "ws://localhost:4892/graphql" } let event = subscription client "get_props" { postAdded: { author: unit, comment: unit } } diff --git a/examples/6-watch-query/generate-purs-schema.mjs b/examples/6-watch-query/generate-purs-schema.mjs index ed9aa2a..3c755b9 100644 --- a/examples/6-watch-query/generate-purs-schema.mjs +++ b/examples/6-watch-query/generate-purs-schema.mjs @@ -9,7 +9,7 @@ export default () => useNewtypesForRecords: false }, [ { - url: 'http://localhost:4000/graphql', + url: 'http://localhost:4892/graphql', moduleName: 'Admin' } ]) diff --git a/examples/6-watch-query/server-fn.js b/examples/6-watch-query/server-fn.js index 43c1909..02afa6a 100644 --- a/examples/6-watch-query/server-fn.js +++ b/examples/6-watch-query/server-fn.js @@ -28,7 +28,7 @@ module.exports = async (onListening) => { comment: String! } `) - const PORT = 4000 + const PORT = 4892 const app = express() app.use('/graphql', bodyParser.json()) @@ -75,7 +75,7 @@ module.exports = async (onListening) => { plugins: [ // Proper shutdown for the HTTP server. ApolloServerPluginDrainHttpServer({ httpServer }), - + // Proper shutdown for the WebSocket server. { async serverWillStart() { diff --git a/examples/6-watch-query/src/Main.purs b/examples/6-watch-query/src/Main.purs index d2c3a1f..5d045f4 100644 --- a/examples/6-watch-query/src/Main.purs +++ b/examples/6-watch-query/src/Main.purs @@ -19,10 +19,10 @@ main :: Effect Unit main = do client :: Client _ Schema <- createSubscriptionClient - { url: "http://localhost:4000/graphql" + { url: "http://localhost:4892/graphql" , authToken: Nothing , headers: [] - , websocketUrl: "ws://localhost:4000/subscriptions" + , websocketUrl: "ws://localhost:4892/subscriptions" } let myQuery = { posts: { author: unit, comment: unit } } @@ -33,9 +33,9 @@ main = do log "Event recieved" logShow e - let - addComment author comment = - let + let + addComment author comment = + let update = updateCacheJson client myQuery \{ posts } -> {posts: posts <> [{author, comment}]} in @@ -47,4 +47,3 @@ main = do launchAff_ do delay $ Milliseconds 25.0 addComment "joe bloggs" "good" - diff --git a/examples/7-field-type-overrides/generate-purs-schema.mjs b/examples/7-field-type-overrides/generate-purs-schema.mjs index f24c726..41dbe04 100644 --- a/examples/7-field-type-overrides/generate-purs-schema.mjs +++ b/examples/7-field-type-overrides/generate-purs-schema.mjs @@ -7,7 +7,7 @@ export default () => dir: "./src/generated", modulePath: ["Generated", "Gql", "Admin"], useNewtypesForRecords: false, - url: "http://localhost:4000/graphql", + url: "http://localhost:4892/graphql", fieldTypeOverrides: { Widget: { special_string: { moduleName: "DataTypes", typeName: "MyNewtype" }, diff --git a/examples/7-field-type-overrides/server-fn.js b/examples/7-field-type-overrides/server-fn.js index 4b84628..75b53d9 100644 --- a/examples/7-field-type-overrides/server-fn.js +++ b/examples/7-field-type-overrides/server-fn.js @@ -8,8 +8,8 @@ module.exports = (onListening) => { type Query { widgets(id: ID): [Widget!]! } - - type Widget { + + type Widget { id: ID special_string: String! } @@ -33,5 +33,5 @@ module.exports = (onListening) => { graphiql: true })) - app.listen(4000, onListening) + app.listen(4892, onListening) } diff --git a/examples/7-field-type-overrides/server.js b/examples/7-field-type-overrides/server.js index b8065c5..333a475 100644 --- a/examples/7-field-type-overrides/server.js +++ b/examples/7-field-type-overrides/server.js @@ -1,4 +1,4 @@ import serverFn from './server-fn.js' serverFn(() => { - console.info('Running a GraphQL API server at http://localhost:4000/graphql') + console.info('Running a GraphQL API server at http://localhost:4892/graphql') }) diff --git a/examples/7-field-type-overrides/src/Main.purs b/examples/7-field-type-overrides/src/Main.purs index bc51ede..8def8d8 100644 --- a/examples/7-field-type-overrides/src/Main.purs +++ b/examples/7-field-type-overrides/src/Main.purs @@ -27,4 +27,4 @@ queryGql :: GqlQuery Nil' OpQuery Query query returns => DecodeJson returns => String -> query -> Aff returns -queryGql = query_ "http://localhost:4000/graphql" (Proxy :: Proxy Query) +queryGql = query_ "http://localhost:4892/graphql" (Proxy :: Proxy Query) diff --git a/examples/8-custom-gql-types/generate-purs-schema.mjs b/examples/8-custom-gql-types/generate-purs-schema.mjs index aacddf1..22ae637 100644 --- a/examples/8-custom-gql-types/generate-purs-schema.mjs +++ b/examples/8-custom-gql-types/generate-purs-schema.mjs @@ -7,7 +7,7 @@ export default () => dir: "./src/generated", modulePath: ["Generated", "Gql", "Admin"], useNewtypesForRecords: false, - url: "http://localhost:4000/graphql", + url: "http://localhost:4892/graphql", gqlToPursTypes: { GqlTypeThatIsAString: { typeName: "String", moduleName: "" }, GqlTypeThatIsAnInt: { typeName: "Int", moduleName: "" }, diff --git a/examples/8-custom-gql-types/server-fn.js b/examples/8-custom-gql-types/server-fn.js index 18f84d3..f9dec3e 100644 --- a/examples/8-custom-gql-types/server-fn.js +++ b/examples/8-custom-gql-types/server-fn.js @@ -9,8 +9,8 @@ module.exports = (onListening) => { prop: GqlTypeThatIsAString widgets(id: ID): [Widget!]! } - - type Widget { + + type Widget { id: ID int: GqlTypeThatIsAnInt name: GqlTypeThatIsAString! @@ -42,5 +42,5 @@ module.exports = (onListening) => { graphiql: true })) - app.listen(4000, onListening) + app.listen(4892, onListening) } diff --git a/examples/8-custom-gql-types/server.js b/examples/8-custom-gql-types/server.js index b8065c5..333a475 100644 --- a/examples/8-custom-gql-types/server.js +++ b/examples/8-custom-gql-types/server.js @@ -1,4 +1,4 @@ import serverFn from './server-fn.js' serverFn(() => { - console.info('Running a GraphQL API server at http://localhost:4000/graphql') + console.info('Running a GraphQL API server at http://localhost:4892/graphql') }) diff --git a/examples/8-custom-gql-types/src/Main.purs b/examples/8-custom-gql-types/src/Main.purs index fcd1c57..4a977d2 100644 --- a/examples/8-custom-gql-types/src/Main.purs +++ b/examples/8-custom-gql-types/src/Main.purs @@ -30,4 +30,4 @@ queryGql :: GqlQuery Nil' OpQuery Query query returns => DecodeJson returns => String -> query -> Aff returns -queryGql = query_ "http://localhost:4000/graphql" (Proxy :: Proxy Query) +queryGql = query_ "http://localhost:4892/graphql" (Proxy :: Proxy Query) diff --git a/examples/9-variables/generate-purs-schema.mjs b/examples/9-variables/generate-purs-schema.mjs index ed9aa2a..3c755b9 100644 --- a/examples/9-variables/generate-purs-schema.mjs +++ b/examples/9-variables/generate-purs-schema.mjs @@ -9,7 +9,7 @@ export default () => useNewtypesForRecords: false }, [ { - url: 'http://localhost:4000/graphql', + url: 'http://localhost:4892/graphql', moduleName: 'Admin' } ]) diff --git a/examples/9-variables/server-fn.js b/examples/9-variables/server-fn.js index 3fa9751..bfbd7e1 100644 --- a/examples/9-variables/server-fn.js +++ b/examples/9-variables/server-fn.js @@ -50,5 +50,5 @@ module.exports = (onListening) => { graphiql: true })) - app.listen(4000, onListening) + app.listen(4892, onListening) } diff --git a/examples/9-variables/server.js b/examples/9-variables/server.js index b8065c5..333a475 100644 --- a/examples/9-variables/server.js +++ b/examples/9-variables/server.js @@ -1,4 +1,4 @@ import serverFn from './server-fn.js' serverFn(() => { - console.info('Running a GraphQL API server at http://localhost:4000/graphql') + console.info('Running a GraphQL API server at http://localhost:4892/graphql') }) diff --git a/examples/9-variables/src/Main.purs b/examples/9-variables/src/Main.purs index e1c309e..4b728dc 100644 --- a/examples/9-variables/src/Main.purs +++ b/examples/9-variables/src/Main.purs @@ -54,4 +54,4 @@ queryGql => String -> query -> Aff returns -queryGql = query_ "http://localhost:4000/graphql" (Proxy :: Proxy Query) +queryGql = query_ "http://localhost:4892/graphql" (Proxy :: Proxy Query) From 4d58b7e142c9e4b2e99d49f0f5f4f29be4feec5a Mon Sep 17 00:00:00 2001 From: Bakhtiyar Neyman Date: Tue, 30 Apr 2024 18:28:27 -0700 Subject: [PATCH 3/6] Add allow wrapping the return result in Identity. Why: Often two very similar types exist in the application. 1) The type returned from the server. 2) The type used by a component. Frequently enough the only difference between the two is that some fields are wrapped in a functor. So if we allow wrapping the results in Identity, we will be able to share the type definition. E.g. type Data f = { id: ID, name: f String } type Return = Data Identity type State = Data (Either Union) Thus Identity fulfills a similar role to ErrorBoundary, but is a newtype. --- spago.dhall | 1 + src/GraphQL/Client/QueryReturns.purs | 7 +++++-- src/GraphQL/Client/ToGqlString.purs | 4 +++- test/GraphQL/Client/QueryReturns.Test.purs | 18 ++++++++++++++++++ 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/spago.dhall b/spago.dhall index 17c2d2e..3384ef8 100644 --- a/spago.dhall +++ b/spago.dhall @@ -29,6 +29,7 @@ You can edit this file as you like. , "halogen-subscriptions" , "heterogeneous" , "http-methods" + , "identity" , "integers" , "lists" , "maybe" diff --git a/src/GraphQL/Client/QueryReturns.purs b/src/GraphQL/Client/QueryReturns.purs index e5037b8..1c5a617 100644 --- a/src/GraphQL/Client/QueryReturns.purs +++ b/src/GraphQL/Client/QueryReturns.purs @@ -8,6 +8,7 @@ module GraphQL.Client.QueryReturns import Prelude +import Data.Identity (Identity(..)) import Data.Maybe (Maybe) import Data.Newtype (class Newtype, unwrap) import Data.Symbol (class IsSymbol) @@ -55,6 +56,8 @@ else instance queryReturnsGqlType :: QueryReturnsAt at a q t => QueryReturnsAt a queryReturnsAtImpl at _ q = queryReturnsAtImpl at (undefined :: a) q else instance queryReturnsApplyDirective :: QueryReturnsAt at a q t => QueryReturnsAt at a (ApplyDirective name args q) t where queryReturnsAtImpl at a _ = queryReturnsAtImpl at a (undefined :: q) +else instance queryReturnsIdentity :: QueryReturnsAt at a q t => QueryReturnsAt at a (Identity q) (Identity t) where + queryReturnsAtImpl at a _ = Identity $ queryReturnsAtImpl at a (undefined :: q) else instance queryReturnErrorBoundary :: QueryReturnsAt at a q t => QueryReturnsAt at a (ErrorBoundary q) (BoundaryResult Unit t) where queryReturnsAtImpl at a _ = ErrorBoundary.Result $ queryReturnsAtImpl at a (undefined :: q) else instance queryReturnsSpread :: @@ -75,9 +78,9 @@ else instance queryReturnsArray :: QueryReturnsAt at a q t => QueryReturnsAt at else instance queryReturnsMaybe :: QueryReturnsAt at a q t => QueryReturnsAt at (Maybe a) q (Maybe t) where queryReturnsAtImpl at _ q = pure $ queryReturnsAtImpl at (undefined :: a) q else instance queryReturnsUnion :: - HMapWithIndex (PropToSchemaType schema) (Record query) (Record returns) => + HMapWithIndex (PropToSchemaType schema) { | query} { | returns } => QueryReturnsAt at (GqlUnion schema) (GqlUnion query) (UnionReturned returns) where - queryReturnsAtImpl at _ _ = undefined + queryReturnsAtImpl _ _ _ = undefined else instance queryReturnsParamsArgs :: ( QueryReturnsAt at t q result , HMapWithIndex (ArgPropToGql params) { | args } s diff --git a/src/GraphQL/Client/ToGqlString.purs b/src/GraphQL/Client/ToGqlString.purs index f9335d4..fc8b906 100644 --- a/src/GraphQL/Client/ToGqlString.purs +++ b/src/GraphQL/Client/ToGqlString.purs @@ -41,6 +41,7 @@ import Data.DateTime as DT import Data.Enum (class BoundedEnum, fromEnum) import Data.FoldableWithIndex (foldlWithIndex) import Data.Function (on) +import Data.Identity (Identity(..)) import Data.List (List) import Data.List as List import Data.Map (Map) @@ -108,6 +109,8 @@ else instance gqlQueryStringApplyDirective :: <> reflectSymbol (Proxy :: Proxy name) <> gqlArgStringRecordTopLevel args <> toGqlQueryStringImpl opts q +else instance gqlQueryStringIdentity :: GqlQueryString a => GqlQueryString (Identity a) where + toGqlQueryStringImpl opts (Identity a) = toGqlQueryStringImpl opts a else instance gqlQueryStringErrorBoundary :: GqlQueryString a => GqlQueryString (ErrorBoundary a) where toGqlQueryStringImpl opts (ErrorBoundary a) = toGqlQueryStringImpl opts a else instance gqlQueryStringSymbol :: IsSymbol s => GqlQueryString (Proxy s) where @@ -484,4 +487,3 @@ else instance isIgnoreArgOrArg :: (IsIgnoreArg l, IsIgnoreArg r) => IsIgnoreArg ArgR r -> isIgnoreArg r else instance isIgnoreArgOther :: IsIgnoreArg a where isIgnoreArg _ = false - diff --git a/test/GraphQL/Client/QueryReturns.Test.purs b/test/GraphQL/Client/QueryReturns.Test.purs index d078707..5b5cc25 100644 --- a/test/GraphQL/Client/QueryReturns.Test.purs +++ b/test/GraphQL/Client/QueryReturns.Test.purs @@ -2,6 +2,7 @@ module GraphQL.Client.QueryReturns.Test where import Prelude +import Data.Identity (Identity(..)) import Data.Maybe (Maybe(..)) import Data.Newtype (class Newtype) import GraphQL.Client.Alias ((:)) @@ -328,6 +329,23 @@ testDirective = =>> { id } } +testIdentity + :: Proxy + { users :: + Array + { id :: Identity Int + } + } +testIdentity = + queryReturns testSchemaProxy + $ + { users: + { is_in_rec: + [ { int: 0 } ] +++ ((ArgR [ ignoreOrStr true, ignoreOrStr false ]) :: OrArg IgnoreArg _) + } + =>> { id: Identity id } + } + ignoreOrStr :: Boolean -> OrArg IgnoreArg From 032b71bd3d2b59ec14b7b4121e8e18b76512bf1d Mon Sep 17 00:00:00 2001 From: Bakhtiyar Neyman Date: Tue, 30 Apr 2024 18:44:39 -0700 Subject: [PATCH 4/6] Extend variable checks to ErrorBoundary, Identity and GqlUnion. --- src/GraphQL/Client/Variables.purs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/GraphQL/Client/Variables.purs b/src/GraphQL/Client/Variables.purs index 3a8219d..eb15945 100644 --- a/src/GraphQL/Client/Variables.purs +++ b/src/GraphQL/Client/Variables.purs @@ -27,6 +27,7 @@ import Prelude import Control.Apply (lift2) import Data.Argonaut.Core (Json, jsonEmptyObject) import Data.Argonaut.Encode (class EncodeJson, encodeJson) +import Data.Identity (Identity) import Data.List (List(..), intercalate) import Data.Maybe (Maybe(..)) import Data.Newtype (class Newtype, unwrap) @@ -142,6 +143,12 @@ else instance getVarOrArg :: varR = getVar (Proxy :: _ r) in lift2 Record.merge varL varR +-- else instance getVarUnion :: +-- ( HFoldl GetVarRec (Proxy {}) { | query } (Proxy { | var }) +-- ) => +-- GetVar (GqlUnion query) { | var } where +-- getVar _ = Proxy -- q >>= \query -> hfoldl GetVarRec (Proxy :: _ {}) (query :: { | query }) + else instance getVarRecord :: ( HFoldl GetVarRec (Proxy {}) { | query } (Proxy { | var }) ) => @@ -220,6 +227,24 @@ else instance varsTypeCheckedWithoutVars :: getVarsJson _ _ = jsonEmptyObject getVarsTypeNames _ _ = "" +else instance varsTypeCheckedIdentity :: + GetVar query {} => + VarsTypeChecked schema (Identity query) where + getVarsJson _ _ = jsonEmptyObject + getVarsTypeNames _ _ = "" + +else instance varsTypeCheckedErrorBoundary :: + GetVar query {} => + VarsTypeChecked schema (ErrorBoundary query) where + getVarsJson _ _ = jsonEmptyObject + getVarsTypeNames _ _ = "" + +else instance varsTypeCheckedUnion :: + GetVar { | query } {} => + VarsTypeChecked schema (GqlUnion query) where + getVarsJson _ _ = jsonEmptyObject + getVarsTypeNames _ _ = "" + else instance varsTypeCheckedSpread :: GetVar (Spread alias arg fields) {} => VarsTypeChecked schema (Spread alias arg fields) where @@ -398,4 +423,3 @@ endsWith c str = removeSuffix :: Char -> String -> String removeSuffix c str = if endsWith c str then String.take (String.length str - 1) str else str - From 7b66ea74f31f59294ade283b88ed1c6184724b63 Mon Sep 17 00:00:00 2001 From: Bakhtiyar Neyman Date: Tue, 30 Apr 2024 19:04:58 -0700 Subject: [PATCH 5/6] Add ArrayOf utility. --- src/GraphQL/Client/ArrayOf.purs | 18 ++++++ src/GraphQL/Client/QueryReturns.purs | 3 + src/GraphQL/Client/ToGqlString.purs | 3 + test/GraphQL/Client/QueryReturns.Test.purs | 66 +++++++++++++++++++--- test/GraphQL/Client/ToGqlString.Test.purs | 11 ++++ 5 files changed, 94 insertions(+), 7 deletions(-) create mode 100644 src/GraphQL/Client/ArrayOf.purs diff --git a/src/GraphQL/Client/ArrayOf.purs b/src/GraphQL/Client/ArrayOf.purs new file mode 100644 index 0000000..c819308 --- /dev/null +++ b/src/GraphQL/Client/ArrayOf.purs @@ -0,0 +1,18 @@ +module GraphQL.Client.ArrayOf + ( ArrayOf (..) + , arrayOf + ) where + +import Data.Newtype (class Newtype) + + +-- | An array type for more control over type inference. +-- +-- This is useful for distinguising between `f (Array a)`` and `Array (f a)` in the return type, +-- where `f` is `Identity` or `ErrorBoundary`. +newtype ArrayOf a = ArrayOf a + +derive instance newtypeArrayOf :: Newtype (ArrayOf a) _ + +arrayOf :: forall q . q -> ArrayOf q +arrayOf = ArrayOf diff --git a/src/GraphQL/Client/QueryReturns.purs b/src/GraphQL/Client/QueryReturns.purs index 1c5a617..4625544 100644 --- a/src/GraphQL/Client/QueryReturns.purs +++ b/src/GraphQL/Client/QueryReturns.purs @@ -15,6 +15,7 @@ import Data.Symbol (class IsSymbol) import GraphQL.Client.Alias (Alias(..)) import GraphQL.Client.Alias.Dynamic (Spread, SpreadRes) import GraphQL.Client.Args (class SatisifyNotNullParam, ArgPropToGql, Args(..)) +import GraphQL.Client.ArrayOf (ArrayOf(..)) import GraphQL.Client.AsGql (AsGql) import GraphQL.Client.Directive (ApplyDirective) import GraphQL.Client.ErrorBoundary (BoundaryResult, ErrorBoundary) @@ -73,6 +74,8 @@ else instance queryReturnsSpreadNewtype :: ) => QueryReturnsAt at newtypeSchema (Spread (Proxy alias) args q) (SpreadRes returns) where queryReturnsAtImpl at _ _ = undefined +else instance queryReturnsArrayOf :: QueryReturnsAt at a q t => QueryReturnsAt at (Array a) (ArrayOf q) (Array t) where + queryReturnsAtImpl at _ (ArrayOf q) = pure $ queryReturnsAtImpl at (undefined :: a) q else instance queryReturnsArray :: QueryReturnsAt at a q t => QueryReturnsAt at (Array a) q (Array t) where queryReturnsAtImpl at _ q = pure $ queryReturnsAtImpl at (undefined :: a) q else instance queryReturnsMaybe :: QueryReturnsAt at a q t => QueryReturnsAt at (Maybe a) q (Maybe t) where diff --git a/src/GraphQL/Client/ToGqlString.purs b/src/GraphQL/Client/ToGqlString.purs index fc8b906..1431988 100644 --- a/src/GraphQL/Client/ToGqlString.purs +++ b/src/GraphQL/Client/ToGqlString.purs @@ -63,6 +63,7 @@ import GraphQL.Client.Alias (Alias(..)) import GraphQL.Client.Alias.Dynamic (Spread(..)) import GraphQL.Client.Args (AndArgs(AndArgs), Args(..), IgnoreArg, OrArg(..)) import GraphQL.Client.Args.AllowedMismatch (AllowedMismatch) +import GraphQL.Client.ArrayOf (ArrayOf(..)) import GraphQL.Client.Directive (ApplyDirective(..)) import GraphQL.Client.ErrorBoundary (ErrorBoundary(..)) import GraphQL.Client.NullArray (NullArray) @@ -113,6 +114,8 @@ else instance gqlQueryStringIdentity :: GqlQueryString a => GqlQueryString (Iden toGqlQueryStringImpl opts (Identity a) = toGqlQueryStringImpl opts a else instance gqlQueryStringErrorBoundary :: GqlQueryString a => GqlQueryString (ErrorBoundary a) where toGqlQueryStringImpl opts (ErrorBoundary a) = toGqlQueryStringImpl opts a +else instance gqlQueryStringArrayOf :: GqlQueryString a => GqlQueryString (ArrayOf a) where + toGqlQueryStringImpl opts (ArrayOf a) = toGqlQueryStringImpl opts a else instance gqlQueryStringSymbol :: IsSymbol s => GqlQueryString (Proxy s) where toGqlQueryStringImpl _ _ = ": " <> reflectSymbol (Proxy :: Proxy s) else instance gqlQueryStringVar :: IsSymbol s => GqlQueryString (Var s a) where diff --git a/test/GraphQL/Client/QueryReturns.Test.purs b/test/GraphQL/Client/QueryReturns.Test.purs index 5b5cc25..2c2b8fe 100644 --- a/test/GraphQL/Client/QueryReturns.Test.purs +++ b/test/GraphQL/Client/QueryReturns.Test.purs @@ -8,6 +8,7 @@ import Data.Newtype (class Newtype) import GraphQL.Client.Alias ((:)) import GraphQL.Client.Alias.Dynamic (Spread(..), SpreadRes) import GraphQL.Client.Args (IgnoreArg(..), NotNull, OrArg(..), (++), (+++), (=>>)) +import GraphQL.Client.ArrayOf (arrayOf) import GraphQL.Client.Directive (applyDir) import GraphQL.Client.NullArray (NullArray(..)) import GraphQL.Client.QueryReturns (class QueryReturns, queryReturns) @@ -338,13 +339,64 @@ testIdentity } testIdentity = queryReturns testSchemaProxy - $ - { users: - { is_in_rec: - [ { int: 0 } ] +++ ((ArgR [ ignoreOrStr true, ignoreOrStr false ]) :: OrArg IgnoreArg _) - } - =>> { id: Identity id } - } + { users: + { is_in_rec: + [ { int: 0 } ] +++ ((ArgR [ ignoreOrStr true, ignoreOrStr false ]) :: OrArg IgnoreArg _) + } + =>> { id: Identity id } + } + +testArrayOf + :: Proxy + { users :: + Array + { id :: Int + } + } +testArrayOf = + queryReturns testSchemaProxy + { users: + { is_in_rec: + [ { int: 0 } ] +++ ((ArgR [ ignoreOrStr true, ignoreOrStr false ]) :: OrArg IgnoreArg _) + } + =>> { id: arrayOf id } + } + +testArrayOfIdentities + :: Proxy + { users :: + Array + ( Identity + { id :: Int + } + ) + } +testArrayOfIdentities = + queryReturns testSchemaProxy + { users: + { is_in_rec: + [ { int: 0 } ] +++ ((ArgR [ ignoreOrStr true, ignoreOrStr false ]) :: OrArg IgnoreArg _) + } + =>> arrayOf (Identity { id }) + } + +testIdentityOfArray + :: Proxy + { users :: + Identity + ( Array + { id :: Int + } + ) + } +testIdentityOfArray = + queryReturns testSchemaProxy + { users: + { is_in_rec: + [ { int: 0 } ] +++ ((ArgR [ ignoreOrStr true, ignoreOrStr false ]) :: OrArg IgnoreArg _) + } + =>> Identity { id } + } ignoreOrStr :: Boolean diff --git a/test/GraphQL/Client/ToGqlString.Test.purs b/test/GraphQL/Client/ToGqlString.Test.purs index 5524b78..64dd8ee 100644 --- a/test/GraphQL/Client/ToGqlString.Test.purs +++ b/test/GraphQL/Client/ToGqlString.Test.purs @@ -5,6 +5,7 @@ import Prelude import GraphQL.Client.Alias ((:)) import GraphQL.Client.Alias.Dynamic (Spread(..)) import GraphQL.Client.Args (IgnoreArg(..), OrArg(..), (++), (+++), (=>>)) +import GraphQL.Client.ArrayOf (arrayOf) import GraphQL.Client.Directive (applyDir) import GraphQL.Client.ToGqlString (gqlArgStringRecordTopLevel, toGqlQueryString, toGqlQueryStringFormatted) import GraphQL.Client.Variable (Var(..)) @@ -260,4 +261,14 @@ spec = `shouldEqual` """@cached { a +}""" + it "ignores arrayOf" $ + toGqlQueryStringFormatted + { foo: { bar: arrayOf unit } + } + `shouldEqual` + """ { + foo { + bar + } }""" From 7fa98627e36a194baaf7ff5b69aefa0fb8dba2bc Mon Sep 17 00:00:00 2001 From: Bakhtiyar Neyman Date: Thu, 13 Jun 2024 19:04:38 -0700 Subject: [PATCH 6/6] Eq and Ord instance on UnionReturned. --- src/GraphQL/Client/Union.purs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/GraphQL/Client/Union.purs b/src/GraphQL/Client/Union.purs index 3332abf..f5b7356 100644 --- a/src/GraphQL/Client/Union.purs +++ b/src/GraphQL/Client/Union.purs @@ -24,6 +24,8 @@ derive instance Newtype (GqlUnion r) _ newtype UnionReturned r = UnionReturned (Variant r) +derive newtype instance Eq (Variant r) => Eq (UnionReturned r) +derive newtype instance Ord (Variant r) => Ord (UnionReturned r) derive instance Newtype (UnionReturned r) _ instance (RL.RowToList r rl, DecodeUnion rl r) => DecodeJson (UnionReturned r) where