Replies: 1 comment
-
Nested arguments are supplemented with gql-custom schemas that inherit from base. We might need to specify ‘… on Repository’ - not sure if this is not always the case Beforegql.query(
(v: { login: string }) => `query getByPinned($login: String!) {
user(login: $login) {
pinnedItems(first: 6, types: REPOSITORY) {
nodes {
... on Repository {
name
owner { login }
id
description
createdAt
stargazerCount
isFork
forkCount
isPrivate
}
}
}
}
}`,
{
user: {
pinnedItems: { nodes: [GqlRepository] },
}
},
) Aftergql.query(
`getByPinned($login: String!)`,
{
user: {
pinnedItems: new schema.Object(
{ nodes: [GqlRepository.join('owner')] },
`pinnedItems(first: 6, types: REPOSITORY)`
)
}
},
); Before`
query {
getItems {
id
name
price
currency
}
}
` Aftergql.query(
`getItems`,
{ getItems: new schema.Collection([Item]) },
); TODO: Check that mutation with Beforeexport const UserResource = {
get: gql.query(
`query GetUser($id: ID!) {
user(id: $id) {
id
name
username
email
phone
website
}
}
`,
{ user: User },
),
update: gql.mutation(
`mutation updateUser($user: User!) {
user(user: $user) {
id
name
username
email
phone
website
}
}`,
{ updateUser: User },
),
}; Afterexport const UserResource = {
get: gql.query(`getUser($id: ID!)`, { user: User }),
update: gql.mutation(`updateUser($user: User!)`, { user: user }),
};
UserResource.update({ id: 'myid', username: 'bob' }); const UserResource = createResource({
schema: Todo,
methods: ['get', 'update'],
}); Schema Include/ExcludeBase definition should include all related fields in schema definition. However, by not including a default value you can (by default) exclude requesting them and joining on them during denormalization. TODO: Make sure denormalization doesn’t require any members that do not have a default value. // defaults to not requesting author
class Post extends GQLEntity {
title = '';
content = '';
static schema = {
author: User,
related: [Post],
}
}
const getPost = gql.query(`getPost($id: ID!)`, { post: Post.join('author', 'related') });
const getPosts = gql.query(
`getPosts($first: Number)`,
{ getPosts: new schema.Collection([Post.join('author')]) }
);
getPost('myid');
getPosts(6); Entity.join
Design Decisions
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This is explore possible ergonomics improvements to GraphQL support. For context, the initial library was built to support 100% of the powers of Rest Hooks high performance high data integrity with helpers built on the low level API. To expand upon GraphQL support more specializations can be created on top of. These of course will always be completely optional.
https://ntucker.notion.site/GQLResource-3879592f59a044f5a461f91ed0cbfb9e
Other previous discussions: #361
Before
After
Before
After
Types can be registered in the construction of base endpoint
Beta Was this translation helpful? Give feedback.
All reactions