Skip to content

Commit

Permalink
Merge branch 'main' into chore/add-storybook-ci-option-to-test-start-…
Browse files Browse the repository at this point in the history
…storybook-ok
  • Loading branch information
virtuoushub committed Oct 15, 2021
2 parents ad51da2 + c32d671 commit 536e541
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 11 deletions.
22 changes: 12 additions & 10 deletions .github/workflows/projects_beta_automation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
- opened

jobs:
add_new_issues_to_projects_beta:
add_incoming_to_projects_beta:
runs-on: ubuntu-latest

steps:
Expand All @@ -25,6 +25,7 @@ jobs:
nodes {
id
name
settings
}
}
}
Expand All @@ -33,14 +34,15 @@ jobs:
echo 'PROJECT_ID='$(jq '.data.organization.projectNext.id' project_data.json) >> $GITHUB_ENV
echo 'STATUS_FIELD_ID='$(jq '.data.organization.projectNext.fields.nodes[] | select(.name=="Status") | .id' project_data.json) >> $GITHUB_ENV
echo 'NEW_ISSUES_OPTION_ID='$(jq '.data.organization.projectNext.fields.nodes[] | select(.name=="Status") | .settings | fromjson.options[] | select(.name=="New issues") | .id' project_data.json) >> $GITHUB_ENV
- name: Set env var for issue
if: github.event_name == 'issue'
run: echo 'CONTENT_ID='${{ github.event.issue.node_id }} >> $GITHUB_ENV
if: github.event_name == 'issues'
run: echo 'CONTENT_ID="${{ github.event.issue.node_id }}"' >> $GITHUB_ENV

- name: Set env var for pull request
if: github.event_name == 'pull_request_target:'
run: echo 'CONTENT_ID='${{ github.event.pull_request.node_id }} >> $GITHUB_ENV
if: github.event_name == 'pull_request_target'
run: echo 'CONTENT_ID="${{ github.event.pull_request.node_id }}"' >> $GITHUB_ENV

- name: Add to project
env:
Expand All @@ -54,25 +56,25 @@ jobs:
}
}
}' -f projectId=$PROJECT_ID -f contentId=$CONTENT_ID --jq '.data.addProjectNextItem.projectNextItem.id')"
echo 'ITEM_ID='$item_id >> $GITHUB_ENV
- name: Set status to "New issues"
env:
GITHUB_TOKEN: ${{ secrets.PROJECTS_BETA_AUTOMATION }}
run: |
gh api graphql --header 'GraphQL-Features: projects_next_graphql' -f query='
mutation ($projectId: ID!, $itemId: ID!, $statusFieldId: ID!) {
mutation ($projectId: ID!, $itemId: ID!, $statusFieldId: ID!, $newIssuesOptionId: String!) {
updateProjectNextItemField(
input: {
projectId: $projectId
itemId: $itemId
fieldId: $statusFieldId
value: "New issues"
value: $newIssuesOptionId
}
) {
projectNextItem {
id
}
}
}' -f projectId=$PROJECT_ID -f itemId=$ITEM_ID -f statusFieldId=$STATUS_FIELD_ID
}' -f projectId=$PROJECT_ID -f itemId=$ITEM_ID -f statusFieldId=$STATUS_FIELD_ID -f newIssuesOptionId=${{ env.NEW_ISSUES_OPTION_ID }}
9 changes: 9 additions & 0 deletions packages/graphql-server/src/plugins/__fixtures__/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ export const testQuery = /* GraphQL */ `
}
`

export const testFilteredQuery = /* GraphQL */ `
query FilteredQuery {
me {
id
name
}
}
`

export const testErrorQuery = /* GraphQL */ `
query forbiddenUserQuery {
forbiddenUser {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import { BaseLogger, LoggerOptions } from 'pino'

import { createLogger } from '@redwoodjs/api/logger'

import { testSchema, testQuery, testErrorQuery } from '../__fixtures__/common'
import {
testSchema,
testQuery,
testErrorQuery,
testFilteredQuery,
} from '../__fixtures__/common'
import { LoggerConfig, useRedwoodLogger } from '../useRedwoodLogger'

const watchFileCreated = (filename) => {
Expand Down Expand Up @@ -132,4 +137,26 @@ describe('Populates context', () => {
expect(errorLogStatement.level).toEqual(50)
expect(errorLogStatement.msg).toEqual('You are forbidden')
})

it('Should not log filtered graphql operations', async () => {
const loggerConfig = {
logger,
options: {
excludeOperations: ['FilteredQuery'],
},
} as LoggerConfig
const testkit = createTestkit([useRedwoodLogger(loggerConfig)], testSchema)
await testkit.execute(testFilteredQuery, {}, {})
await watchFileCreated(logFile)

const logStatements = parseLogFile(logFile)

expect(logStatements).not.toEqual(
expect.arrayContaining([
expect.objectContaining({
msg: expect.stringContaining('FilteredQuery'),
}),
])
)
})
})
15 changes: 15 additions & 0 deletions packages/graphql-server/src/plugins/useRedwoodLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { RedwoodGraphQLContext } from '../functions/types'
* @param query - Include the query. This is the query or mutation (with fields) made in the request.
* @param tracing - Include the tracing and timing information.
* @param userAgent - Include the browser (or client's) user agent.
* @param excludeOperations - Exclude the specified operations from being logged.
*
*/
type GraphQLLoggerOptions = {
/**
Expand Down Expand Up @@ -88,6 +90,14 @@ type GraphQLLoggerOptions = {
* This can be helpful to know what type of client made the request to resolve issues when encountering errors or unexpected behavior.
*/
userAgent?: boolean

/**
* @description Exclude operation from the log output.
*
* This is useful when you want to filter out certain operations from the log output.
* For example `IntrospectionQuery` from GraphQL playground.
*/
excludeOperations?: string[]
}

/**
Expand Down Expand Up @@ -192,6 +202,7 @@ export const useRedwoodLogger = (
const includeRequestId = loggerConfig?.options?.requestId
const includeUserAgent = loggerConfig?.options?.userAgent
const includeQuery = loggerConfig?.options?.query
const excludeOperations = loggerConfig.options?.excludeOperations

return {
onPluginInit(context) {
Expand All @@ -210,6 +221,10 @@ export const useRedwoodLogger = (
const operationName =
args.operationName || rootOperation.name?.value || 'Anonymous Operation'

if (excludeOperations?.includes(operationName)) {
return
}

if (includeOperationName) {
options['operationName'] = operationName
}
Expand Down

0 comments on commit 536e541

Please sign in to comment.