Skip to content

Commit

Permalink
I think it is OK now
Browse files Browse the repository at this point in the history
  • Loading branch information
danieljharvey committed Apr 5, 2020
1 parent 6d67809 commit 8713672
Show file tree
Hide file tree
Showing 10 changed files with 8,536 additions and 10 deletions.
Empty file added output/github/.gitkeep
Empty file.
8,427 changes: 8,427 additions & 0 deletions output/github/output.ts

Large diffs are not rendered by default.

Empty file added output/twitter/.gitkeep
Empty file.
82 changes: 82 additions & 0 deletions output/twitter/output.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import * as fc from "fast-check";
export const getArbitraryQuery = (): fc.Arbitrary<any> =>
fc.record({
Tweet: getArbitraryTweet(),
Tweets: fc.array(getArbitraryTweet()),
TweetsMeta: getArbitraryMeta(),
User: getArbitraryUser(),
Notifications: fc.array(getArbitraryNotification()),
NotificationsMeta: getArbitraryMeta(),
});

export const getArbitraryID = (): fc.Arbitrary<any> => fc.string();

export const getArbitraryTweet = (): fc.Arbitrary<any> =>
fc.record({
id: getArbitraryID(),
body: getArbitraryString(),
date: getArbitraryDate(),
Author: getArbitraryUser(),
Stats: getArbitraryStat(),
});

export const getArbitraryString = (): fc.Arbitrary<any> => fc.string();

export const getArbitraryDate = (): fc.Arbitrary<any> => fc.string();

export const getArbitraryUser = (): fc.Arbitrary<any> =>
fc.record({
id: getArbitraryID(),
username: getArbitraryString(),
first_name: getArbitraryString(),
last_name: getArbitraryString(),
full_name: getArbitraryString(),
name: getArbitraryString(),
avatar_url: getArbitraryUrl(),
});

export const getArbitraryUrl = (): fc.Arbitrary<any> => fc.string();

export const getArbitraryStat = (): fc.Arbitrary<any> =>
fc.record({
views: getArbitraryInt(),
likes: getArbitraryInt(),
retweets: getArbitraryInt(),
responses: getArbitraryInt(),
});

export const getArbitraryInt = (): fc.Arbitrary<any> => fc.integer();

export const getArbitraryMeta = (): fc.Arbitrary<any> =>
fc.record({ count: getArbitraryInt() });

export const getArbitraryNotification = (): fc.Arbitrary<any> =>
fc.record({
id: getArbitraryID(),
date: getArbitraryDate(),
type: getArbitraryString(),
});

export const getArbitraryMutation = (): fc.Arbitrary<any> =>
fc.record({
createTweet: getArbitraryTweet(),
deleteTweet: getArbitraryTweet(),
markTweetRead: getArbitraryBoolean(),
});

export const getArbitraryBoolean = (): fc.Arbitrary<any> => fc.boolean();

export const getArbitraryActionExecutionCapabilitySetting = (): fc.Arbitrary<
any
> =>
fc.oneof(
fc.constant("ALL_ACTIONS"),
fc.constant("DISABLED"),
fc.constant("LOCAL_ACTIONS_ONLY"),
fc.constant("NO_POLICY")
);

export const getArbitraryAddCommentInput = (): fc.Arbitrary<any> => fc.string();

export const getArbitraryStatOrNotification = (): fc.Arbitrary<any> =>
fc.oneof(getArbitraryStat(), getArbitraryNotification());
22 changes: 17 additions & 5 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
# die if anything goes wrong
set -euxo pipefail

# remove old output so it doesn't get typechecked
echo "export const a = 1" | tee ./output/output.ts
# replace twitter output with something that typechecks
echo "export const a = 1" | tee ./output/twitter/output.ts

# replace github output with something that typechecks
echo "export const a = 1" | tee ./output/github/output.ts

# install shit
yarn install

# run tests
yarn test
Expand All @@ -13,10 +19,16 @@ yarn test
yarn build

# run codegen basic
yarn graphql-codegen --config ./test/codegen.yml
yarn graphql-codegen --config ./test/twitter/codegen.yml

# typecheck result
yarn tsc --noEmit ./output/output.ts
yarn tsc --noEmit ./output/twitter/output.ts

# run codegen advanced
yarn graphql-codegen --config ./test/github/codegen.yml

# typecheck advanced result
yarn tsc --noEmit ./output/github/output.ts

# output some shit
# output some shit (only from the basic one, the advanced one blows the stack)
yarn ts-node ./output/test-output.ts
5 changes: 0 additions & 5 deletions test/codegen.yml

This file was deleted.

5 changes: 5 additions & 0 deletions test/github/codegen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
schema: ./test/github/github-schema.graphql
# documents: './src/**/*.graphql'
generates:
./output/github/output.ts:
- ./dist/src/index.js
File renamed without changes.
5 changes: 5 additions & 0 deletions test/twitter/codegen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
schema: ./test/twitter/twitter-schema.graphql
# documents: './src/**/*.graphql'
generates:
./output/twitter/output.ts:
- ./dist/src/index.js
File renamed without changes.

0 comments on commit 8713672

Please sign in to comment.