Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
TODO: update all errors we want to expose to the outside world to be GraphQLYogaError objects
  • Loading branch information
tibetsprague committed Sep 20, 2022
1 parent 5acb9d3 commit 68f4e88
Show file tree
Hide file tree
Showing 3 changed files with 332 additions and 344 deletions.
47 changes: 24 additions & 23 deletions api/graphql/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,36 @@ import { merge, reduce } from 'lodash'

const schemaText = readFileSync(join(__dirname, 'schema.graphql')).toString()

export const createRequestHandler = () =>
createServer({
plugins: [useLazyLoadedSchema(createSchema)],
context: async ({ query, req, variables }) => {
if (process.env.DEBUG_GRAPHQL) {
sails.log.info('\n' +
red('graphql query start') + '\n' +
query + '\n' +
red('graphql query end')
)
sails.log.info(inspect(variables))
}

if (req.session.userId) {
await User.query().where({ id: req.session.userId }).update({ last_active_at: new Date() })
}
},
graphiql: true
})

function createSchema (expressContext) {
const { req } = expressContext
const session = req.session
const { api_client, session } = req
const userId = session.userId
const isAdmin = Admin.isSignedIn(req)
const models = makeModels(userId, isAdmin, req.api_client)
const models = makeModels(userId, isAdmin, api_client)
const { resolvers, fetchOne, fetchMany } = setupBridge(models)

let allResolvers
if (req.api_client) {
if (api_client) {
// TODO: check scope here, just api:write, just api_read, or both?
allResolvers = {
Query: makeApiQueries(fetchOne),
Expand All @@ -123,6 +143,7 @@ function createSchema (expressContext) {
}
} else {
// authenticated users

allResolvers = {
Query: makeAuthenticatedQueries(userId, fetchOne, fetchMany),
Mutation: makeMutations(expressContext, userId, isAdmin, fetchOne),
Expand Down Expand Up @@ -444,26 +465,6 @@ export function makeApiMutations () {
}
}

export const createRequestHandler = () =>
createServer({
plugins: [useLazyLoadedSchema(createSchema)],
context: async ({ query, req, variables }) => {
if (process.env.DEBUG_GRAPHQL) {
sails.log.info('\n' +
red('graphql query start') + '\n' +
query + '\n' +
red('graphql query end')
)
sails.log.info(inspect(variables))
}

if (req.session.userId) {
await User.query().where({ id: req.session.userId }).update({ last_active_at: new Date() })
}
},
graphiql: true
})

let modelToTypeMap

function getTypeForInstance (instance, models) {
Expand Down
Loading

0 comments on commit 68f4e88

Please sign in to comment.