<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=490755098261949&amp;ev=PageView&amp;noscript=1">

NEW CASE STUDY: See how we built a custom digital platform for Melissa Wood Health

GraphQL — Omit table from generating under ‘graphiql’. Postgres smart comments.

Pratik Agashe
Author Pratik Agashe
Published On Jun 16, 2020
featured_graph_QL

Introduction

Before we start, I would like to give a quick background story behind this post. This is a sub-post of the “Building Full-stack web app with PostGraphile and React”. So I have used related table names.

As we know GraphQL is an open-source data query and manipulation language for APIs, and a runtime for fulfilling queries with existing data.

Graphiql is a graphical interactive in-browser GraphQL IDE. You can see all available queries and mutations based on our schema, which is given to the client.

But what if you want to omit some table from generating their mutations from graphql?

If you are using Postgres then you can add smart comments for particular a table. That will omit or exclude that table from generating its mutation.

There are two ways to add smart comments.

First:

  1. Open `sql shell (psql)`- This is a command line tool for psql. It will ask you which table you want to select. Enter table name: in our case postgres-graphql.
  2. Now run following commands and graphql will remove mutation from auto generated graphiql.

1t6AGtj4dyGZCFjGLyKKIDg@2x
Reference to add Smart Comment from SQL Shell (psql)

Second:

  1. Open pgAdmin.
  2. Navigate to your database -> schema (public) -> table list.
  3. Now right click on table knex_migration and select properties
  4. One popup will open. Under comments, add the following lines.

 

@name knex_migrations
@omit create,update,delete
This is the documentation.

5. Follow the same process for knex_migrations_lock, and paste the following lines.

@name knex_migrations_lock
@omit create,update,delete
This is the documentation.

 

1xvq4_8kKplKWAjxD5WXIWw@2x

Reference to add Smart Comment from pgAdmin 4

That’s it!

Now when we reload our graphiql, we’ll find the mutations for these tables are no longer there.

Thanks!

ins13_2image2X

Interested in a career at Heady?

Excellent! We are always looking for great talent.

app-clips_1
app-clips_2

Interested in a career at Heady?

Excellent! We are always looking for great talent.

LET'S TALK IT OUT.

Figuring out your next step? We're here for you.

Or drop us a line.

hello@heady.io