-
-
Notifications
You must be signed in to change notification settings - Fork 29
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
graphql-tag integration #8
Labels
discussion
Help your opinion
Comments
agree. I'd say gql-tag usage is more probable than a user wanting a plain string output. So it should default to returning gql-tag. I'd model it something like: const getUserGqlTag = graphqlify.query({ getUser: ... })
const getUserString = graphqlify.query.asString({ getUser: ... }) because then user can choose string/gql-tag for each individual query. |
Thank you for your response.
|
fwiw, I use this little helper: /* ./lib/to-operation.ts */
import { gql } from '@apollo/client';
import { CompiledResult } from 'typed-graphqlify';
export const toOperation = <D, V>(value: CompiledResult<D, V>) =>
gql(value.toString()); /* ./lib/gql-operation.ts */
import { CompiledResult } from 'typed-graphqlify';
import { toOperation } from './to-operation';
export class GqlOperation<D, V> {
constructor(public tag: CompiledResult<D, V>) {}
get type(): D {
return this.tag.result.data;
}
get operation() {
return toOperation(this.tag);
}
} /* ./domain/post.ts */
import { query, types } from 'typed-graphqlify';
import { GqlOperation } from '../lib/gql-operation';
export const getPostQuery = new GqlOperation(
query('getPost', {
post: {
name: types.string,
},
})
);
export const getPostsQuery = new GqlOperation(
query('getPosts', {
post: {
name: types.string,
},
})
); export function PostList(props: PropsWithChildren<PostListProps>) {
const { loading, error, data } = useQuery<typeof getPostsQuery.type>(
getPostsQuery.operation
);
return (
<StyledPostList>
<h2>Post List</h2>
{JSON.stringify({ loading, error, data })}
{props.children}
</StyledPostList>
);
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I would like to keep this library thin, but every time writing
is annoying, so it would be great to have
gql
compatible mode.If we implement it, the code should be like this:
The text was updated successfully, but these errors were encountered: