-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #88 from brandonchinn178/test-codegen
Fix ambiguous field name error
- Loading branch information
Showing
20 changed files
with
195 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
gen/ |
18 changes: 18 additions & 0 deletions
18
graphql-client/test/Data/GraphQL/Test/Generation/TestGeneration.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
schema: schema.graphql | ||
documents: queries/*.graphql | ||
|
||
hsSourceDir: gen/ | ||
apiModule: Example.API | ||
enumsModule: Example.Enums | ||
scalarsModule: Example.Scalars |
8 changes: 8 additions & 0 deletions
8
graphql-client/test/Data/GraphQL/Test/Generation/queries/basic.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
query getUsers { | ||
users { | ||
id | ||
name | ||
age | ||
gender | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
graphql-client/test/Data/GraphQL/Test/Generation/queries/duplicate-names.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
query getAge($name: String!) { | ||
userByName(name: $name) { | ||
age | ||
} | ||
} | ||
|
||
query getGender($name: String!) { | ||
userByName(name: $name) { | ||
gender | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
20 changes: 20 additions & 0 deletions
20
graphql-client/test/Data/GraphQL/Test/Generation/schema.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
16 changes: 16 additions & 0 deletions
16
graphql-client/test/Data/GraphQL/Test/Generation/src/Example/Scalars.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.