npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

graphql-starter-kit

v1.0.0

Published

Prisma is used to connect a GraphQL server to a persistent data store. To set up Prisma locally, follow the steps below.

Downloads

4

Readme

GraphQL

How to use this demo

Setting up Prisma

Prisma is used to connect a GraphQL server to a persistent data store. To set up Prisma locally, follow the steps below.

  1. Run the following commands:
npm add prisma -g
prisma deploy --new
  1. Select Demo server + MySQL database and follow the prompts in the terminal. You may have to create an Prisma account. Once this has finished, note that your endpoint has been created and referenced in prisma.yml.

  2. Generate the Prisma client with the command below. This will create the library that will allow you to read / write using Prisma.

prisma generate
  1. Any time a change is made to your Prisma datamodel, you must re-run
prisma deploy

This will re-generate your client library as well, so all the changes you made to the datamodel are reflected.

  1. Now, you can use the Prisma client by including the following line at the top of your files.
const { prisma } = require('./generated/prisma-client')

To use the client, you will access the imported Prisma object from the context object and call your functions like so:

context.prisma.createUser({firstName: "Brad", lastName: "Pitt"})
context.prisma.users()

Deploying the GraphQL server

From the root directory of the downloaded package, run

node ./src/index.js

to deploy the server.

If you make changes to the code, press Ctrl+C in the console and re-run this command to re-deploy the server.

More about GraphQL

schema.graphql

This is where you will define your desired schema. Each field in the schema must have a corresponding resolver (defined in /src/resolvers/).

'Query' and 'Mutation' are called root types. If a root field returns a user-defined type (e.g., 'user()' must return an object of type User), then the flow is as follows:

  • resolver for the root field is executed ('user(id: ID!): User')
  • an object of type User is returned
  • resolvers for the fields on the User object are executed

As an important note, the end results of a GraphQL query must be scalar types. In the example above, the user() query does not return the object because it is a User type, so the next level-down of resolvers are executed and return scalar types (ID, string).

Resolvers

Resolvers define how your queries will be executed. Think of these as basic function definitions which contain the logic of what should happen when the queries are performed. Again, each field in your schema must have a resolver so GraphQL can know what to do when you query on them.

Every resolver receives 4 arguments (in this order):

  • root / parent--contains the result of the parent field's resolver
  • args--the arguments passed to the field in the query you wrote
  • context--shared by all resolvers in the query. Allows resolvers to communicate
  • info--contains information about the execution state of the query, including the field name, path to the field from the root

As you build out your schema, remember to create resolvers for the things you have added. If you are using Prisma to read/write to a database, take advantage of the functions in the Prisma client library in your resolvers. You can access these functions by importing the library and accessing it from the context object (e.g., "context.prisma.createUser()").

Refer to the examples in src/resolvers/ as a starting point.

More about Prisma

datamodel.prisma

Files ending in .prisma use GraphQL schema definition language (SDL) so this will look very similar to your schema.graphql file. In general, these files should match. A note: the '@id' directive in datamodel.prisma tells Prisma to autogenerate a GUID for records of type Link. Similarly, '@createdAt' tells Prisma to autogenerate a timestamp for the 'createdAt' field.

prisma.yml

This file points Prisma to the HTTP endpoint for your API, the Prisma datamodel, and specifies which language the client should be generated in and where it should be located (https://www.howtographql.com/graphql-js/4-adding-a-database/). When the prisma deploy command is executed, your endpoint will automatically populate.

Sources

  • https://www.howtographql.com/
  • https://www.prisma.io/docs/1.34/get-started/01-setting-up-prisma-new-database-JAVASCRIPT-a002/
  • https://www.prisma.io/docs/prisma-client/basic-data-access/writing-data-JAVASCRIPT-rsc6/