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

Refactor/rename skip to offset #294

Merged
merged 17 commits into from
Jul 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions docs/asciidoc/guides/migration-guide/queries.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Changes to note for migration:
* Query fields were previously named in the singular, and in _PascalCase_ - they are now pluralized and in _camelCase_
* Query return types were previously in nullable lists of nullable types - they are now non-nullable lists of non-nullable types, _e.g._ `[Movie]` is now `[Movie!]!`; ensuring either an array of defined `Movie` objects or an empty array.
* In this example, the `_MovieFilter` type has essentially been renamed to `MovieWhere`, the `filter` arguments renamed to `where`, and the top-level field arguments `title` and `averageRating` removed - see <<migration-guide-queries-filtering>> below
* The `first`, `offset` and `orderBy` have been collapsed into the `MovieOptions` type and renamed `limit`, `skip` and `sort`, respectively - see <<migration-guide-queries-options>> below
* The `first`, `offset` and `orderBy` have been collapsed into the `MovieOptions` type and renamed `limit`, `offset` and `sort`, respectively - see <<migration-guide-queries-options>> below

[[migration-guide-queries-filtering]]
== Filtering (`where`)
Expand Down Expand Up @@ -206,7 +206,7 @@ Using `@neo4j/graphql`, this will now be:
[source, graphql]
----
query {
movies(options: { skip: 20, limit: 10 }) {
movies(options: { offset: 20, limit: 10 }) {
title
}
}
Expand Down
4 changes: 2 additions & 2 deletions docs/asciidoc/ogm/getting-started.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ const User = ogm.model("User");

const app = express();
app.get("/users", async (req, res) => {
const { search, skip, limit, sort } = req.query;
const { search, offset, limit, sort } = req.query;

const regex = search ? `(?i).*${search}.*` : null;

const users = await User.find({
where: { name_REGEX: regex },
options: {
skip,
offset,
limit,
sort
}
Expand Down
10 changes: 5 additions & 5 deletions docs/asciidoc/schema/pagination.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

== Page-based pagination

Page-based pagination can be achieved through the use of the `skip` and `limit` options available whilst querying for data.
Page-based pagination can be achieved through the use of the `offset` and `limit` options available whilst querying for data.

Using the following type definition:

Expand All @@ -27,14 +27,14 @@ query {
}
----

And then on subsequent calls, introduce the `skip` argument and increment it by 10 on each call.
And then on subsequent calls, introduce the `offset` argument and increment it by 10 on each call.

Page 2:
[source, graphql]
----
query {
users(options: {
skip: 10
offset: 10
limit: 10
}) {
name
Expand All @@ -47,7 +47,7 @@ Page 3:
----
query {
users(options: {
skip: 20
offset: 20
limit: 10
}) {
name
Expand All @@ -67,7 +67,7 @@ query {
}) {
name
posts(options: {
skip: 20
offset: 20
limit: 10
}) {
content
Expand Down
2 changes: 1 addition & 1 deletion docs/asciidoc/schema/sorting.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ input MovieOptions {
"""Specify one or more MovieSort objects to sort Movies by. The sorts will be applied in the order in which they are arranged in the array."""
sort: [MovieSort]
limit: Int
skip: Int
offset: Int
}

type Query {
Expand Down
6 changes: 3 additions & 3 deletions examples/neo-push/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ Once logged in users are directed to the dashboard page;
![dashboard](assets/dashboard.jpg)

```graphql
query myBlogs($id: ID, $skip: Int, $limit: Int, $hasNextBlogsSkip: Int) {
query myBlogs($id: ID, $offset: Int, $limit: Int, $hasNextBlogsoffset: Int) {
myBlogs: blogs(
where: { OR: [{ creator: { id: $id } }, { authors: { id: $id } }] }
options: { limit: $limit, skip: $skip, sort: { createdAt: DESC } }
options: { limit: $limit, offset: $offset, sort: { createdAt: DESC } }
) {
id
name
Expand All @@ -159,7 +159,7 @@ query myBlogs($id: ID, $skip: Int, $limit: Int, $hasNextBlogsSkip: Int) {
where: { OR: [{ creator: { id: $id } }, { authors: { id: $id } }] }
options: {
limit: 1
skip: $hasNextBlogsSkip
offset: $hasNextBlogsoffset
sort: { createdAt: DESC }
}
) {
Expand Down
12 changes: 6 additions & 6 deletions examples/neo-push/client/src/components/Blog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ function CreatePost({ close, blog }: { close: () => void; blog: BlogInterface })

function BlogPosts({ blog }: { blog: BlogInterface }) {
const { query } = useContext(graphql.Context);
const [skip, setSkip] = useState(0);
const [offset, setOffset] = useState(0);
const [limit] = useState(10);
const [hasMore, setHasMore] = useState(false);
const [posts, setPosts] = useState<PostInterface[]>([]);
Expand All @@ -150,9 +150,9 @@ function BlogPosts({ blog }: { blog: BlogInterface }) {
query: BLOG_POSTS,
variables: {
blog: blog.id,
skip: posts.length,
offset: posts.length,
limit,
hasNextPostsSkip: posts.length === 0 ? limit : posts.length + 1,
hasNextPostsOffset: posts.length === 0 ? limit : posts.length + 1,
},
});

Expand All @@ -161,11 +161,11 @@ function BlogPosts({ blog }: { blog: BlogInterface }) {
} catch (e) {}

setLoading(false);
}, [skip, posts]);
}, [offset, posts]);

useEffect(() => {
getPosts();
}, [skip]);
}, [offset]);

if (loading) {
<Card className="mt-3 p-3">
Expand All @@ -190,7 +190,7 @@ function BlogPosts({ blog }: { blog: BlogInterface }) {
</Row>
{hasMore && (
<div className="d-flex justify-content-center w-100">
<Button onClick={() => setSkip((s) => s + 1)}>Load More</Button>
<Button onClick={() => setOffset((s) => s + 1)}>Load More</Button>
</div>
)}
</Card>
Expand Down
24 changes: 12 additions & 12 deletions examples/neo-push/client/src/components/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ function BlogItem(props: { blog: any; updated?: boolean }) {
function MyBlogs() {
const { getId } = useContext(auth.Context);
const { query } = useContext(graphql.Context);
const [skip, setSkip] = useState(0);
const [offset, setOffset] = useState(0);
const [limit] = useState(10);
const [myBlogsHasMore, setMyBlogsHasMore] = useState(false);
const [blogs, setBlogs] = useState<BlogInterface[]>([]);
Expand All @@ -128,9 +128,9 @@ function MyBlogs() {
query: MY_BLOGS,
variables: {
id: getId(),
skip: blogs.length,
offset: blogs.length,
limit,
hasNextBlogsSkip: blogs.length === 0 ? limit : blogs.length + 1,
hasNextBlogsOffset: blogs.length === 0 ? limit : blogs.length + 1,
},
});

Expand All @@ -139,11 +139,11 @@ function MyBlogs() {
} catch (e) {}

setLoading(false);
}, [skip, blogs, limit]);
}, [offset, blogs, limit]);

useEffect(() => {
getBlogs();
}, [skip]);
}, [offset]);

if (loading) {
<Card className="mt-3 p-3">
Expand All @@ -163,7 +163,7 @@ function MyBlogs() {
))}
</Row>
{myBlogsHasMore && (
<div className="d-flex justify-content-center w-100" onClick={() => setSkip((s) => s + 1)}>
<div className="d-flex justify-content-center w-100" onClick={() => setOffset((s) => s + 1)}>
<Button>Load More</Button>
</div>
)}
Expand All @@ -174,7 +174,7 @@ function MyBlogs() {
function RecentlyUpdatedBlogs() {
const { query } = useContext(graphql.Context);
const [limit] = useState(10);
const [skip, setSkip] = useState(0);
const [offset, setOffset] = useState(0);
const [myBlogsHasMore, setMyBlogsHasMore] = useState(false);
const [blogs, setBlogs] = useState<BlogInterface[]>([]);
const [loading, setLoading] = useState(true);
Expand All @@ -185,9 +185,9 @@ function RecentlyUpdatedBlogs() {
const response = await query({
query: RECENTLY_UPDATED_BLOGS,
variables: {
skip: blogs.length,
offset: blogs.length,
limit,
hasNextBlogsSkip: blogs.length === 0 ? limit : blogs.length + 1,
hasNextBlogsOffset: blogs.length === 0 ? limit : blogs.length + 1,
},
});

Expand All @@ -196,11 +196,11 @@ function RecentlyUpdatedBlogs() {
} catch (e) {}

setLoading(false);
}, [skip, blogs]);
}, [offset, blogs]);

useEffect(() => {
getBlogs();
}, [skip]);
}, [offset]);

if (loading) {
<Card className="mt-3 p-3">
Expand All @@ -220,7 +220,7 @@ function RecentlyUpdatedBlogs() {
))}
</Row>
{myBlogsHasMore && (
<div className="d-flex justify-content-center w-100" onClick={() => setSkip((s) => s + 1)}>
<div className="d-flex justify-content-center w-100" onClick={() => setOffset((s) => s + 1)}>
<Button>Load More</Button>
</div>
)}
Expand Down
12 changes: 6 additions & 6 deletions examples/neo-push/client/src/components/Post.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ function PostComments({
setComments: (cb: (comments: Comment[]) => any) => void;
}) {
const { query } = useContext(graphql.Context);
const [skip, setSkip] = useState(0);
const [offset, setOffset] = useState(0);
const [limit] = useState(10);
const [hasMore, setHasMore] = useState(false);
const [loading, setLoading] = useState(true);
Expand All @@ -408,9 +408,9 @@ function PostComments({
query: POST_COMMENTS,
variables: {
post,
skip: comments.length,
offset: comments.length,
limit,
hasNextCommentsSkip: comments.length === 0 ? limit : comments.length + 1,
hasNextCommentsOffset: comments.length === 0 ? limit : comments.length + 1,
},
});

Expand All @@ -423,11 +423,11 @@ function PostComments({
}

setLoading(false);
}, [skip]);
}, [offset]);

useEffect(() => {
getComments();
}, [skip]);
}, [offset]);

if (error) {
return (
Expand Down Expand Up @@ -463,7 +463,7 @@ function PostComments({
))}
{hasMore && (
<div className="d-flex justify-content-center w-100 mt-3">
<Button onClick={() => setSkip((s) => s + 1)}>Load More</Button>
<Button onClick={() => setOffset((s) => s + 1)}>Load More</Button>
</div>
)}
</>
Expand Down
24 changes: 12 additions & 12 deletions examples/neo-push/client/src/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ export const CREATE_BLOG = gql`
`;

export const MY_BLOGS = gql`
query myBlogs($id: ID, $skip: Int, $limit: Int, $hasNextBlogsSkip: Int) {
query myBlogs($id: ID, $offset: Int, $limit: Int, $hasNextBlogsOffset: Int) {
myBlogs: blogs(
where: { OR: [{ creator: { id: $id } }, { authors: { id: $id } }] }
options: { limit: $limit, skip: $skip, sort: { createdAt: DESC } }
options: { limit: $limit, offset: $offset, sort: { createdAt: DESC } }
) {
id
name
Expand All @@ -48,16 +48,16 @@ export const MY_BLOGS = gql`
}
hasNextBlogs: blogs(
where: { OR: [{ creator: { id: $id } }, { authors: { id: $id } }] }
options: { limit: 1, skip: $hasNextBlogsSkip, sort: { createdAt: DESC } }
options: { limit: 1, offset: $hasNextBlogsOffset, sort: { createdAt: DESC } }
) {
id
}
}
`;

export const RECENTLY_UPDATED_BLOGS = gql`
query recentlyUpdatedBlogs($skip: Int, $limit: Int, $hasNextBlogsSkip: Int) {
recentlyUpdatedBlogs: blogs(options: { limit: $limit, skip: $skip, sort: { updatedAt: DESC } }) {
query recentlyUpdatedBlogs($offset: Int, $limit: Int, $hasNextBlogsOffset: Int) {
recentlyUpdatedBlogs: blogs(options: { limit: $limit, offset: $offset, sort: { updatedAt: DESC } }) {
id
name
creator {
Expand All @@ -66,7 +66,7 @@ export const RECENTLY_UPDATED_BLOGS = gql`
}
updatedAt
}
hasNextBlogs: blogs(options: { limit: 1, skip: $hasNextBlogsSkip, sort: { updatedAt: DESC } }) {
hasNextBlogs: blogs(options: { limit: 1, offset: $hasNextBlogsOffset, sort: { updatedAt: DESC } }) {
id
}
}
Expand Down Expand Up @@ -155,10 +155,10 @@ export const POST = gql`
`;

export const BLOG_POSTS = gql`
query blogPosts($blog: ID, $skip: Int, $limit: Int, $hasNextPostsSkip: Int) {
query blogPosts($blog: ID, $offset: Int, $limit: Int, $hasNextPostsOffset: Int) {
blogPosts: posts(
where: { blog: { id: $blog } }
options: { skip: $skip, limit: $limit, sort: { createdAt: DESC } }
options: { offset: $offset, limit: $limit, sort: { createdAt: DESC } }
) {
id
title
Expand All @@ -169,7 +169,7 @@ export const BLOG_POSTS = gql`
}
hasNextPosts: posts(
where: { blog: { id: $blog } }
options: { skip: $hasNextPostsSkip, limit: 1, sort: { createdAt: DESC } }
options: { offset: $hasNextPostsOffset, limit: 1, sort: { createdAt: DESC } }
) {
id
}
Expand Down Expand Up @@ -201,10 +201,10 @@ export const COMMENT_ON_POST = gql`
`;

export const POST_COMMENTS = gql`
query postComments($post: ID, $skip: Int, $limit: Int, $hasNextCommentsSkip: Int) {
query postComments($post: ID, $offset: Int, $limit: Int, $hasNextCommentsOffset: Int) {
postComments: comments(
where: { post: { id: $post } }
options: { skip: $skip, limit: $limit, sort: { createdAt: ASC } }
options: { offset: $offset, limit: $limit, sort: { createdAt: ASC } }
) {
id
author {
Expand All @@ -217,7 +217,7 @@ export const POST_COMMENTS = gql`
}
hasNextComments: comments(
where: { post: { id: $post } }
options: { skip: $hasNextCommentsSkip, limit: 1, sort: { createdAt: ASC } }
options: { offset: $hasNextCommentsOffset, limit: 1, sort: { createdAt: ASC } }
) {
id
}
Expand Down
6 changes: 3 additions & 3 deletions packages/graphql/src/schema/make-augmented-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function makeAugmentedSchema(
const queryOptions = composer.createInputTC({
name: "QueryOptions",
fields: {
skip: "Int",
offset: "Int",
limit: "Int",
},
});
Expand Down Expand Up @@ -450,13 +450,13 @@ function makeAugmentedSchema(
type: sortInput.List,
},
limit: "Int",
skip: "Int",
offset: "Int",
},
});
} else {
composer.createInputTC({
name: `${node.name}Options`,
fields: { limit: "Int", skip: "Int" },
fields: { limit: "Int", offset: "Int" },
});
}

Expand Down
Loading