question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Code First Approach with Nexus-Prisma

See original GitHub issue

I’m submitting a…


[ ] Regression 
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

Nestjs Graphql uses the “Schema-First” approach to define the Graphql Api. Prisma and Prisma-Client can be used in connection with Nestjs to build the Graphql Api.

Expected behavior

Nestjs Graphql can use the “Resolver/Code-First” approach to define the Graphql Api. Prisma released the nexus-prisma plugin to generate the Graphql Schema based on the implemented resolvers using the prisma-client under the hood and inside the resolvers. Furthermore, it is compatible with e.g. apollo-server.

Minimal reproduction of the problem with instructions

I created a project with nestjs, prisma-client and nexus-prisma. You can find it here https://github.com/marcjulian/nestjs-prisma-nexus. The Schema generation with nexus-prisma works for exposing and hiding queries and fields. However, I couldn’t add a custom query using Nestjs Resolver and Query.

The Schema is setup inside GraphqlConfigService located in src/prisma.

Here is an example:

I am exposing all queries from the prisma api to the nestjs api and I am adding a custom helloWorld query.

const Query = prismaObjectType({
            name: 'Query',
            definition(t) {
                t.prismaFields(['*'])

                t.field('helloWorld', {
                    type: 'String',
                    resolve: (_, { id }, ctx) =>{
                        return 'Hello World'
                    }
                });
            }
        });

You can call the query from the Nestjs Playground and you receive Hello World.

Instead of defining the custom query inside of GraphqlConfigService I would like to use a resolver for example AppResolver:

@Resolver()
export class AppResolver {

    constructor() {

    }

    @Query()
    helloWorld() {
        return 'Hello World!';
    }
}

The approach with the Resolver doesn’t work because nexus-prisma doesn’t know about the custom Query. How can I use a Query inside a Resolver and use nexus-prisma to generate the custom query to the Graphql Schema?

What is the motivation / use case for changing the behavior?

The motivation to use Resolver and Query, Mutation and Subscription is to use the existing features of Nestjs such as guards andinterceptors.

Environment


Nest version: X.Y.Z

 
For Tooling issues:
- Node version: XX  
- Platform:  

Others:

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:18
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
marcjuliancommented, May 29, 2019

Sorry for my late reply. Yes the code first approach of 6.0.0 with type-graphql is much cleaner. I like the concept of decorators.

1reaction
VienNguyen113commented, Jan 4, 2020

@kamilmysliwiec with nexus-prisma we can easily expose prisma generated query+mutation instead of using prisma-binding

Read more comments on GitHub >

github_iconTop Results From Across the Web

GraphQL Nexus: Code-First GraphQL Server Development
Today we are introducing a library that implements the code-first approach for GraphQL server development: GraphQL Nexus.
Read more >
Code-first GraphQL with Nexus - Resilient Tech - Medium
We develop our GraphQL schema using a code-first approach with a library called Nexus. Nexus documentation talks about developing GraphQL schema in a...
Read more >
Code-first Prisma schema API · Issue #227 - GitHub
I understand that Prisma is a cross language tool (Go driver for example) but it is also written in JS and Generator and...
Read more >
How to create a GraphQL API with Prisma and Nexus
Nexus is a declarative, code first approach to writing GraphQL schemas. It's created by a team at Prisma and works seamlessly with it....
Read more >
Code first GraphQL Server Development with Prisma - YouTube
At Prisma, we have been highly involved with the GraphQL tooling ecosystem over the past few years. In this talk, we share our...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found