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.

Better handling of API-only vs DB-only vs both fields in schemas

See original GitHub issue

In Vulcan, any field can be included in:

  • the database
  • the API
  • both

But currently, that distinction is not very clear, and in fact it’s not even possible to declare a field to be made available through the API but not insertable in the database at all.

It’s all a bit messy, so here is a proposal for a better system.

  1. We keep the existing schema object passed to createCollection for any field that should be included in the database. We keep the current canRead-based permission check to know whether those fields should also be made available through the API.
  2. We support a new apiSchema object that contains fields that should only exist in the API, and not the database.

There are two advantages to this approach:

  1. We are able to distinguish between the two kinds of fields.
  2. We can simplify the syntax for API-only fields:

Before:

const schema = {
  pagePath: {
    type: String,
    optional: true,
    canRead: ["guests"],
    resolveAs: {
      typeName: "String",
      resolver: (post, args, context) => {
        return getPostPageLink(post, false);
      },
  }
}

After:

const apiSchema = {
  pagePath: {
    typeName: "String",
    resolver: () => {...},
  },
}

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
SachaGcommented, May 14, 2020

This also means moving relation out of resolveAs, which probably makes sense anyway.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Do's and Don'ts for your schema and GraphQL operations
Learn GraphQL with Apollo Odyssey, our hands-on training and tutorial course platform - https://odyssey.apollographql.com/Learn from our ...
Read more >
The Do's and Don'ts for your Schema and GraphQL Operations
Presented by Michael Watson, Customer Success Engineer, ApolloLearn best practices for your GraphQL schema and client operations.
Read more >
warthog - npm
With Warthog, set up your data models and resolvers, and it does the rest. ... Generate typescript classes and GraphQL schema yarn warthog ......
Read more >
Using Rails for API-only Applications - Ruby on Rails Guides
Handled at the middleware layer: Reloading: Rails applications support transparent reloading. This works even if your application gets big and restarting the ...
Read more >
Content management in Next.js with Sanity CMS
Editing the Sanity.io schemas. Schemas are at the core of structured content modeling in Sanity.io and refer to the field types that a...
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