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

Graphql example #93

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open

Conversation

Beigelman
Copy link

Overview

This PR addresses issue #89 creating a working GraphQL example

Screanshot

image

@talyssonoc talyssonoc changed the title Graphql exemple Graphql example Oct 12, 2021
src/_boot/graphql.ts Outdated Show resolved Hide resolved
src/_lib/graphql/schema.ts Outdated Show resolved Hide resolved
src/_lib/graphql/schema.ts Outdated Show resolved Hide resolved
src/_lib/graphql/schema.ts Outdated Show resolved Hide resolved
src/_lib/graphql/schema.ts Outdated Show resolved Hide resolved
Comment on lines 56 to 62
return request()
.post('/graphql')
.send({
operationName: 'Articles',
query: getArticlesQuery,
variables,
})
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about adding some abstraction to make it easier to send GraphQL calls in a test?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it could be interesting. Do you have something in mind?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have the implementation per se in mind, but we could have something that would be used like this:

  return query('Articles', queryArticlesQuery, variables)
    .expect(async (res) => {
      // ...
    })

And something similar to mutations as well. What do you think?

@@ -0,0 +1,32 @@
import { Registry } from '@/container';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid importing app-specific code into _lib code.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see another way to do this at the moment.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could move the type GraphQLContext to inside the module file since it's app-specific.

src/article/index.ts Outdated Show resolved Hide resolved
const { findArticles } = context.container;
const { filter, pagination, sort } = args;

const { data: articles } = await findArticles({ filter, pagination, sort });
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we should add some way to pass to the query which attributes we want according to the GraphQL query?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understood your question correctly I think this is up to the client to deal with/decide

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is (and it's what is already happening), but we should also avoid fetching from the database the attributes the client does not want, right?

src/_boot/graphql.ts Outdated Show resolved Hide resolved
src/_boot/graphql.ts Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants