Skip to content
This repository was archived by the owner on May 26, 2023. It is now read-only.
This repository was archived by the owner on May 26, 2023. It is now read-only.

Doubts using gqlgen for graphql endpoint #9

Open
@frederikhors

Description

@frederikhors

@eminetto thanks for your project.

https://github.com/bxcodec/go-clean-arch is a similar one and I opened a PR (bxcodec/go-clean-arch#39) for understand how to use https://github.com/99designs/gqlgen with Clean Architecture.

Is gqlgen in this case just a "third party" delivery layer?

I don't know if I'm doing this well: I'm using just graphql dir in root!

Because - as you can see - code is generated I can just inject usecases in main.go for the graphql.Resolver{}:

e.POST("graphql", echo.WrapHandler(handler.GraphQL(graphql.NewExecutableSchema(graphql.Config{Resolvers: &graphql.Resolver{
    ArticleUsecase: au,
    // <--- other usecases here --->
}}))))

and I use that usecases in resolver.go:

func (r *queryResolver) Articles(ctx context.Context) ([]*models.Article, error) {
	articles, _, err := r.ArticleUsecase.Fetch(ctx, "cursor", 1) // <--- example values because I don't want to change Usecase now
	return articles, err
}

What do you think about?

  1. Am I respecting the principles of "clean architecture"?

  2. Is there a more elegant solution?


A more extensive example of gqlgen in action can be found here: https://github.com/oshalygin/gqlgen-pg-todo-example.
As you can see he's injecting db *pg.DB in main.go file for

Resolvers: &resolvers.Resolver{
	DB: db,
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions