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.

Add top-level `context` to services

See original GitHub issue

From my quick pseudo code from our call:

import { PrismaClient } from '@prisma/client'
import { RedwoodContext} from '@redwoodjs/api'

const db = new PrismaClient()
const context = new RedwoodContext()

export const posts = () => {
  return db.post.findMany()
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
chris-hailstormcommented, Apr 24, 2020

Here’s a simple example that seems to work – adds indicated:

/* api/src/functions/graphql.js */

import {
  createGraphQLHandler,
  makeMergedSchema,
  makeServices,
} from '@redwoodjs/api'

import importAll from '@redwoodjs/api/importAll.macro'

import { db } from 'src/lib/db'

const schemas = importAll('api', 'graphql')
const services = importAll('api', 'services')

// new
const context = ({context, event}) => {
  console.log('GraphQL custom context handler')
  console.log(context)
  console.log(event)
  return context
}

export const handler = createGraphQLHandler({
  schema: makeMergedSchema({
    schemas,
    services: makeServices({ services }),
  }),
  context,  // new
  db,
})

Now I’m trying to figure out how to get more info into the context from the client side.

0reactions
peterpcommented, Apr 24, 2020

@chris-hailstorm The event contains a bunch of useful things, but I think mostly the way of getting stuff from web -> api (especially authentication tokens) would be to add them to the headers of apollo graphql client.

I need to look into how we do that via the Redwood Providers. It may not be technically possible right now, but I need to double check that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Top-level statements - C# tutorial - Microsoft Learn
This tutorial shows how you can use top-level statements to experiment and prove concepts while exploring your ideas.
Read more >
C# 9.0 Support for Top-level programs in Visual Studio 2019
NET 5 a new feature is getting introduced called "Top-level programs". This functionality takes away a lot of the boilerplate code necessary ...
Read more >
Contexts - GitHub Docs
You can access context information in workflows and actions. ... github, object, The top-level context available during any job or step in a...
Read more >
Compose file version 3 reference - Docker Documentation
Top-level keys that define a section in the configuration file such as build , deploy , depends_on ... version: "3.9" services: webapp: build:...
Read more >
Creating a Windows Service with .NET 6
Windows services are programs that are automatically started when the system starts up, or when the user logs in. They run in the...
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