Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Foolproof Relay Pagination API #113

Draft
wants to merge 83 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
d156e2f
Add temporary type to example.
dillonkearns Feb 21, 2019
ad8895b
Use paginationArguments helper.
dillonkearns Feb 21, 2019
2f8a5ba
Add example paginator to generated code as prototype.
dillonkearns Feb 21, 2019
000411c
Clean up example.
dillonkearns Feb 21, 2019
28d166a
Add helper function for paginated searches.
dillonkearns Feb 21, 2019
767f0b9
Move type into library.
dillonkearns Feb 21, 2019
a70f45a
Reverse list in example.
dillonkearns Feb 21, 2019
17e1545
Include page info in helper function.
dillonkearns Feb 21, 2019
1db867f
Change formatting.
dillonkearns Feb 21, 2019
6a3b6cd
Remove unused code.
dillonkearns Feb 21, 2019
4f36802
Assume list for PaginatedData type.
dillonkearns Feb 21, 2019
2321f1d
Include pagination setup in data type.
dillonkearns Feb 21, 2019
6d7c7aa
Store pagination data in model.
dillonkearns Feb 21, 2019
5f337b7
Rename type.
dillonkearns Feb 21, 2019
e698878
Fix issue in paginator.
dillonkearns Feb 21, 2019
6dabfd0
Update pagination code.
dillonkearns Feb 21, 2019
008be9e
Pass in paginator to helper function.
dillonkearns Feb 21, 2019
2872543
Allow pagination size to be set.
dillonkearns Feb 21, 2019
d2ccee7
Rename module.
dillonkearns Feb 21, 2019
dbd539b
Append to list paging within helper.
dillonkearns Feb 21, 2019
4c354fd
Remove comment.
dillonkearns Feb 21, 2019
e3cc9dd
Add another pagination example.
dillonkearns Feb 21, 2019
7aae1d4
Extract internal function.
dillonkearns Feb 21, 2019
0fed02d
Include stargazer metadata in example.
dillonkearns Feb 22, 2019
5f495bf
Show whether done loading or not in example.
dillonkearns Feb 22, 2019
c87d718
Show number loaded so far.
dillonkearns Feb 22, 2019
3fc6f70
Rename record field in example.
dillonkearns Feb 22, 2019
4c3fad8
Rename field in pagination module to be direction-agnostic.
dillonkearns Feb 22, 2019
990d87f
Remove unused variable in example.
dillonkearns Feb 22, 2019
1502ead
Fix pagination to check hasPreviousPage for Backward pagination.
dillonkearns Feb 22, 2019
2cce475
Make paginated stargazer connection take a SelectionSet on the Edge.
dillonkearns Feb 22, 2019
d650cab
Add some test case boilerplate for Connection definition detection.
dillonkearns Feb 23, 2019
feff533
Add test case, change expected type of connection detection function.
dillonkearns Feb 23, 2019
db72e38
Check for spec violations.
dillonkearns Feb 23, 2019
decbbfc
Add helper to define type definitions.
dillonkearns Feb 23, 2019
4070552
Add type annotation.
dillonkearns Feb 23, 2019
f5fd970
Pass in all type definitions to check.
dillonkearns Feb 23, 2019
5dea1c0
Extract page info definition example in test.
dillonkearns Feb 23, 2019
069c182
Fix up some fields in test.
dillonkearns Feb 23, 2019
e972468
Remove type variable for cursor in PaginatedData.
dillonkearns Feb 24, 2019
837a91d
Rename module.
dillonkearns Feb 24, 2019
77c538c
Rename custom type variants.
dillonkearns Feb 24, 2019
2e3108a
Create forward constructor for PagiantedData.
dillonkearns Feb 24, 2019
e6e5a7f
Create backward paginator constructor.
dillonkearns Feb 24, 2019
a9382d0
Use Custom Type to represent PaginatedData.
dillonkearns Feb 24, 2019
d89c8ee
Rename PaginatedData to Paginator.
dillonkearns Feb 24, 2019
2719e3f
Add phantom type to allow limiting arguments to only one direction in…
dillonkearns Feb 24, 2019
9ecdef1
Reorder file.
dillonkearns Feb 24, 2019
40a33b8
Use direction in new paginator selection set.
dillonkearns Feb 24, 2019
e9d81f5
Remove comment.
dillonkearns Feb 24, 2019
a776f83
Fix error in example.
dillonkearns Feb 25, 2019
ce1e5a7
Remove exposed low-level type.
dillonkearns Feb 25, 2019
e7548d3
Rename internal types.
dillonkearns Feb 25, 2019
a5f220d
Rename pagination "data" to more domain-appropriate "nodes".
dillonkearns Feb 25, 2019
a8e6606
Add test setup for pagination.
dillonkearns Feb 25, 2019
b5315bd
Update elm-test version.
dillonkearns Feb 25, 2019
33a5255
Make test green.
dillonkearns Feb 25, 2019
8979930
Decode field within nodes.
dillonkearns Feb 25, 2019
3e5d5e5
Extract selection.
dillonkearns Feb 25, 2019
d755894
Add test helper for pagination tests.
dillonkearns Feb 25, 2019
fd8bcf8
Extract helper function to create json.
dillonkearns Feb 25, 2019
c1abed1
Capture failing test case.
dillonkearns Feb 25, 2019
94addae
Ordering for backwards matches ordering from server now.
dillonkearns Feb 25, 2019
bc600f9
Add test case for forward pagination.
dillonkearns Feb 26, 2019
e84621f
Fix test cases.
dillonkearns Feb 26, 2019
2f114e1
Fix forward pagination list appending order.
dillonkearns Feb 26, 2019
df660f9
Add correct example of connection in test.
dillonkearns Apr 13, 2019
34ba9d9
Change isConnection to test fields.
dillonkearns Apr 13, 2019
e67a9dd
Extract functions.
dillonkearns Apr 13, 2019
562d240
Test isPageInfo.
dillonkearns Apr 13, 2019
0d44142
Test isPageInfo for single items in the test.
dillonkearns Apr 13, 2019
f0cff4f
Remove duplicate.
dillonkearns Apr 13, 2019
27d96d7
Extract function.
dillonkearns Apr 13, 2019
9467ec4
Add todo list comment.
dillonkearns Apr 13, 2019
0aa80ea
Hand-generate full stargazers paginated form.
dillonkearns Apr 14, 2019
3b55e98
Remove unused arg and type.
dillonkearns Apr 14, 2019
17800ae
Add generated code for pagination example.
dillonkearns Apr 14, 2019
d41c380
Change hand-generated code.
dillonkearns Apr 14, 2019
ccc55dc
Remove unecessary cases.
dillonkearns Apr 14, 2019
6b7a1a4
Fill out more details for generator for paginator.
dillonkearns Apr 14, 2019
3c01c45
Add helper function for adding pageInfo optional args.
dillonkearns Apr 14, 2019
4fdf059
Update code example to use new paginator syntax.
dillonkearns Apr 14, 2019
3823b87
Add total count selection to illustrate selecting other fields from c…
dillonkearns Apr 14, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"source-directories": [
"../src",
"src",
"gen",
"src/complex"
],
"elm-version": "0.19.0",
Expand Down Expand Up @@ -35,4 +36,4 @@
"direct": {},
"indirect": {}
}
}
}
52 changes: 52 additions & 0 deletions examples/gen/Pages/Enum/CacheControlScope.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
-- Do not manually edit this file, it was auto-generated by dillonkearns/elm-graphql
-- https://github.com/dillonkearns/elm-graphql


module Pages.Enum.CacheControlScope exposing (CacheControlScope(..), decoder, list, toString)

import Json.Decode as Decode exposing (Decoder)


{-|

- Public -
- Private -

-}
type CacheControlScope
= Public
| Private


list : List CacheControlScope
list =
[ Public, Private ]


decoder : Decoder CacheControlScope
decoder =
Decode.string
|> Decode.andThen
(\string ->
case string of
"PUBLIC" ->
Decode.succeed Public

"PRIVATE" ->
Decode.succeed Private

_ ->
Decode.fail ("Invalid CacheControlScope type, " ++ string ++ " try re-running the @dillonkearns/elm-graphql CLI ")
)


{-| Convert from the union type representating the Enum to a string that the GraphQL server will recognize.
-}
toString : CacheControlScope -> String
toString enum =
case enum of
Public ->
"PUBLIC"

Private ->
"PRIVATE"
10 changes: 10 additions & 0 deletions examples/gen/Pages/InputObject.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- Do not manually edit this file, it was auto-generated by dillonkearns/elm-graphql
-- https://github.com/dillonkearns/elm-graphql


module Pages.InputObject exposing (placeholder)


placeholder : String
placeholder =
""
10 changes: 10 additions & 0 deletions examples/gen/Pages/Interface.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- Do not manually edit this file, it was auto-generated by dillonkearns/elm-graphql
-- https://github.com/dillonkearns/elm-graphql


module Pages.Interface exposing (placeholder)


placeholder : String
placeholder =
""
21 changes: 21 additions & 0 deletions examples/gen/Pages/Object.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-- Do not manually edit this file, it was auto-generated by dillonkearns/elm-graphql
-- https://github.com/dillonkearns/elm-graphql


module Pages.Object exposing (PageInfo(..), StargazerConnection(..), StargazerEdge(..), User(..))


type PageInfo
= PageInfo


type StargazerConnection
= StargazerConnection


type StargazerEdge
= StargazerEdge


type User
= User
43 changes: 43 additions & 0 deletions examples/gen/Pages/Object/PageInfo.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
-- Do not manually edit this file, it was auto-generated by dillonkearns/elm-graphql
-- https://github.com/dillonkearns/elm-graphql


module Pages.Object.PageInfo exposing (endCursor, hasNextPage, hasPreviousPage, starCursor)

import Graphql.Internal.Builder.Argument as Argument exposing (Argument)
import Graphql.Internal.Builder.Object as Object
import Graphql.Internal.Encode as Encode exposing (Value)
import Graphql.Operation exposing (RootMutation, RootQuery, RootSubscription)
import Graphql.OptionalArgument exposing (OptionalArgument(..))
import Graphql.SelectionSet exposing (SelectionSet)
import Json.Decode as Decode
import Pages.InputObject
import Pages.Interface
import Pages.Object
import Pages.Scalar
import Pages.ScalarCodecs
import Pages.Union


{-| -}
endCursor : SelectionSet (Maybe String) Pages.Object.PageInfo
endCursor =
Object.selectionForField "(Maybe String)" "endCursor" [] (Decode.string |> Decode.nullable)


{-| -}
hasNextPage : SelectionSet Bool Pages.Object.PageInfo
hasNextPage =
Object.selectionForField "Bool" "hasNextPage" [] Decode.bool


{-| -}
hasPreviousPage : SelectionSet Bool Pages.Object.PageInfo
hasPreviousPage =
Object.selectionForField "Bool" "hasPreviousPage" [] Decode.bool


{-| -}
starCursor : SelectionSet (Maybe String) Pages.Object.PageInfo
starCursor =
Object.selectionForField "(Maybe String)" "starCursor" [] (Decode.string |> Decode.nullable)
37 changes: 37 additions & 0 deletions examples/gen/Pages/Object/StargazerConnection.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
-- Do not manually edit this file, it was auto-generated by dillonkearns/elm-graphql
-- https://github.com/dillonkearns/elm-graphql


module Pages.Object.StargazerConnection exposing (edges, pageInfo, totalCount)

import Graphql.Internal.Builder.Argument as Argument exposing (Argument)
import Graphql.Internal.Builder.Object as Object
import Graphql.Internal.Encode as Encode exposing (Value)
import Graphql.Operation exposing (RootMutation, RootQuery, RootSubscription)
import Graphql.OptionalArgument exposing (OptionalArgument(..))
import Graphql.SelectionSet exposing (SelectionSet)
import Json.Decode as Decode
import Pages.InputObject
import Pages.Interface
import Pages.Object
import Pages.Scalar
import Pages.ScalarCodecs
import Pages.Union


{-| -}
edges : SelectionSet decodesTo Pages.Object.StargazerEdge -> SelectionSet (List decodesTo) Pages.Object.StargazerConnection
edges object_ =
Object.selectionForCompositeField "edges" [] object_ (identity >> Decode.list)


{-| -}
pageInfo : SelectionSet decodesTo Pages.Object.PageInfo -> SelectionSet decodesTo Pages.Object.StargazerConnection
pageInfo object_ =
Object.selectionForCompositeField "pageInfo" [] object_ identity


{-| -}
totalCount : SelectionSet Int Pages.Object.StargazerConnection
totalCount =
Object.selectionForField "Int" "totalCount" [] Decode.int
31 changes: 31 additions & 0 deletions examples/gen/Pages/Object/StargazerEdge.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
-- Do not manually edit this file, it was auto-generated by dillonkearns/elm-graphql
-- https://github.com/dillonkearns/elm-graphql


module Pages.Object.StargazerEdge exposing (cursor, node)

import Graphql.Internal.Builder.Argument as Argument exposing (Argument)
import Graphql.Internal.Builder.Object as Object
import Graphql.Internal.Encode as Encode exposing (Value)
import Graphql.Operation exposing (RootMutation, RootQuery, RootSubscription)
import Graphql.OptionalArgument exposing (OptionalArgument(..))
import Graphql.SelectionSet exposing (SelectionSet)
import Json.Decode as Decode
import Pages.InputObject
import Pages.Interface
import Pages.Object
import Pages.Scalar
import Pages.ScalarCodecs
import Pages.Union


{-| -}
cursor : SelectionSet String Pages.Object.StargazerEdge
cursor =
Object.selectionForField "String" "cursor" [] Decode.string


{-| -}
node : SelectionSet decodesTo Pages.Object.User -> SelectionSet decodesTo Pages.Object.StargazerEdge
node object_ =
Object.selectionForCompositeField "node" [] object_ identity
25 changes: 25 additions & 0 deletions examples/gen/Pages/Object/User.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
-- Do not manually edit this file, it was auto-generated by dillonkearns/elm-graphql
-- https://github.com/dillonkearns/elm-graphql


module Pages.Object.User exposing (name)

import Graphql.Internal.Builder.Argument as Argument exposing (Argument)
import Graphql.Internal.Builder.Object as Object
import Graphql.Internal.Encode as Encode exposing (Value)
import Graphql.Operation exposing (RootMutation, RootQuery, RootSubscription)
import Graphql.OptionalArgument exposing (OptionalArgument(..))
import Graphql.SelectionSet exposing (SelectionSet)
import Json.Decode as Decode
import Pages.InputObject
import Pages.Interface
import Pages.Object
import Pages.Scalar
import Pages.ScalarCodecs
import Pages.Union


{-| -}
name : SelectionSet String Pages.Object.User
name =
Object.selectionForField "String" "name" [] Decode.string
56 changes: 56 additions & 0 deletions examples/gen/Pages/Query.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
-- Do not manually edit this file, it was auto-generated by dillonkearns/elm-graphql
-- https://github.com/dillonkearns/elm-graphql


module Pages.Query exposing (StargazersOptionalArguments, stargazers)

import Graphql.Internal.Builder.Argument as Argument exposing (Argument)
import Graphql.Internal.Builder.Object as Object
import Graphql.Internal.Encode as Encode exposing (Value)
import Graphql.Operation exposing (RootMutation, RootQuery, RootSubscription)
import Graphql.OptionalArgument exposing (OptionalArgument(..))
import Graphql.Paginator as Paginator exposing (Paginator)
import Graphql.SelectionSet exposing (SelectionSet)
import Json.Decode as Decode exposing (Decoder)
import Pages.InputObject
import Pages.Interface
import Pages.Object
import Pages.Object.StargazerConnection
import Pages.Scalar
import Pages.ScalarCodecs
import Pages.Union


type alias StargazersOptionalArguments =
{ after : OptionalArgument String
, before : OptionalArgument String
, first : OptionalArgument Int
, last : OptionalArgument Int
}


{-|

- after -
- before -
- first -
- last -

-}
stargazers :
Int
-> Paginator direction decodesTo
-> (StargazersOptionalArguments -> StargazersOptionalArguments)
-> SelectionSet decodesTo Pages.Object.StargazerEdge
-> SelectionSet (Paginator direction decodesTo) Pages.Object.User
stargazers pageSize paginator fillInOptionals object_ =
let
filledInOptionals =
fillInOptionals { first = Absent, after = Absent, last = Absent, before = Absent }
|> Paginator.addPageInfo pageSize paginator

optionalArgs =
[ Argument.optional "first" filledInOptionals.first Encode.int, Argument.optional "after" filledInOptionals.after Encode.string, Argument.optional "last" filledInOptionals.last Encode.int, Argument.optional "before" filledInOptionals.before Encode.string ]
|> List.filterMap identity
in
Object.selectionForCompositeField "stargazers" optionalArgs (Paginator.selectionSet pageSize paginator (Pages.Object.StargazerConnection.edges object_)) identity
50 changes: 50 additions & 0 deletions examples/gen/Pages/Scalar.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
-- Do not manually edit this file, it was auto-generated by dillonkearns/elm-graphql
-- https://github.com/dillonkearns/elm-graphql


module Pages.Scalar exposing (Codecs, Upload(..), defaultCodecs, defineCodecs, unwrapCodecs, unwrapEncoder)

import Graphql.Codec exposing (Codec)
import Graphql.Internal.Builder.Object as Object
import Graphql.Internal.Encode
import Json.Decode as Decode exposing (Decoder)
import Json.Encode as Encode


type Upload
= Upload String


defineCodecs :
{ codecUpload : Codec valueUpload }
-> Codecs valueUpload
defineCodecs definitions =
Codecs definitions


unwrapCodecs :
Codecs valueUpload
-> { codecUpload : Codec valueUpload }
unwrapCodecs (Codecs unwrappedCodecs) =
unwrappedCodecs


unwrapEncoder getter (Codecs unwrappedCodecs) =
(unwrappedCodecs |> getter |> .encoder) >> Graphql.Internal.Encode.fromJson


type Codecs valueUpload
= Codecs (RawCodecs valueUpload)


type alias RawCodecs valueUpload =
{ codecUpload : Codec valueUpload }


defaultCodecs : RawCodecs Upload
defaultCodecs =
{ codecUpload =
{ encoder = \(Upload raw) -> Encode.string raw
, decoder = Object.scalarDecoder |> Decode.map Upload
}
}
19 changes: 19 additions & 0 deletions examples/gen/Pages/ScalarCodecs.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- Do not manually edit this file, it was auto-generated by dillonkearns/elm-graphql
-- https://github.com/dillonkearns/elm-graphql


module Pages.ScalarCodecs exposing (Upload, codecs)

import Json.Decode as Decode exposing (Decoder)
import Pages.Scalar exposing (defaultCodecs)


type alias Upload =
Pages.Scalar.Upload


codecs : Pages.Scalar.Codecs Upload
codecs =
Pages.Scalar.defineCodecs
{ codecUpload = defaultCodecs.codecUpload
}
10 changes: 10 additions & 0 deletions examples/gen/Pages/Union.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- Do not manually edit this file, it was auto-generated by dillonkearns/elm-graphql
-- https://github.com/dillonkearns/elm-graphql


module Pages.Union exposing (placeholder)


placeholder : String
placeholder =
""
Loading