Skip to content

venn-city/poc-nexus-prisma

Repository files navigation

POC - Nexus prisma

Nexus Introduction:

Declarative, code-first and strongly typed GraphQL schema construction for TypeScript & JavaScript:

  • Code first approach: define GraphQL types in JS or TS via code
  • Compatible with the GraphQL ecosystem
  • Type-safe: enable auto-completion and error checks
  • Generate SDL and TS definitions

See more documentation here

More interesting articles:

nexus-prisma

Plugin which connect prisma and GraqphQL Nexus => happiness Generates CRUD building blocks from our prisma data model Nice tutorial to get an idea of how it works

POC Summary

Goals
  • Understand the advantages of the code-first approach
  • Understand the scope of this change in persistency
prisma-nexus-poc repo
  • implement basic schema: User, Transaction, Bill
  • adapt the model to the persistency structure
  • Be excited to all the options and the modularity prisma-nexus allows!
Conclusions
  • generate new entities is very easy and quick
  • add computed field and joined entity in one place
  • the resolver file is very thin !
  • almost everything is generated
  • Only customize resolvers for computed fields and joined entities

Example of the resolver-file of a new entity:

const { prismaObjectType } = require("nexus-prisma");

// resolvers are generated by the templates
const queriesAndMutationsWhitelist = [user,users,usersConnection,createUser,updateUser];

// Entity object: schema def, computed fields, joined fields -- need to be completed
export const User = prismaObjectType({
    name: "User",
    definition(t) {
        t.prismaFields({filter: ["socialSecurityNumber"]});
        // computed fields
        t.string("fullName", {
            resolve: ({firstName, lastName}, args, ctx) =>  firstName + " " + lastName,
        });
    }
});
const userEntityQueriesAndMutation = initializeEntityQueriesAndMutation({entityName: "user", queriesAndMutationsWhitelist});

export const { userQueries, userMutations  } = userEntityQueriesAndMutation;

For now, this repo is just a draft and we can use to play with it and test the nexus-prisma library. Start a local server by running npm run start

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published