Code Monkey home page Code Monkey logo

prisma-graphql-starter's Introduction

If you are trying to understand the codebase this might help.

Graphql Prisma Bindings

Prisma Binding provides a high level API to interact with database.

Talking about prisma.js file

  • Query Operations

Just use prisma.query to query anything.

Example We can pass query in the parameters.

Parameters => (Operation_args, selection_set)

// Promise Version
prisma.query.users(null, '{ id name posts {id title body} }').then(data => {
  console.log(JSON.stringify(data, undefined, 2));
});

//async-await version.
const users = async () => {
  const usersList = await prisma.query.users(
    null,
    '{ id name posts {id title body} }'
  );
  return usersList;
};

usersList
  .then(users => {
    console.log(JSON.stringify(data, undefined, 2));
  })
  .catch(e => {
    console.log(e);
  });
  • Mutation Operations

Just use prisma.mutation to perform mutation operations.

// Promise Version
prisma.mutation
  .updatePost({
    data: {
      title: 'This is updated',
      body: 'Its updated!!! from dsef..',
      published: true
    },
    where: {
      id: 'cjures4qi00380789t104pvi2'
    }
  })
  .then(data => {
    console.log(JSON.stringify(undefined, data, 2));
  });

// Async-await version.
const updatePostForUser = async (postId, data) => {
  const postExists = prisma.exists.Post({
    id: postId
  });

  if (!postExists) {
    throw new Error('Post not exists');
  }
  const author = await prisma.mutation.updatePost(
    {
      data: {
        ...data
      },
      where: {
        id: postId
      }
    },
    '{ author { id name email } }'
  );

  return author;
};
  • Exists

    To check if some data exists it returns true or false. Example:
const postExists = prisma.exists.Post({
  id: postId
});

const userExists = prisma.exists.User({
  id: 'abc123'
});

prisma-graphql-starter's People

Contributors

pranjalagni avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.