forked from getsentry/develop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
doc: PoC of loading event schema docs from Relay (getsentry#96)
- Loading branch information
Showing
14 changed files
with
371 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "src/data-schemas"] | ||
path = src/data-schemas | ||
url = https://github.com/getsentry/sentry-data-schemas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
const { readFileSync } = require('fs'); | ||
const { quicktype, InputData, JSONSchemaInput, JSONSchemaStore } = require("@untitaker/quicktype-core-with-markdown"); | ||
|
||
exports.sourceNodes = async ({ actions, createNodeId, createContentDigest }) => { | ||
const { createNode } = actions; | ||
|
||
let content; | ||
try { | ||
content = readFileSync('./src/data-schemas/relay/event.schema.json', {encoding: "utf8"}); | ||
} catch (e) { | ||
console.warn(`Failed to read Relay event schema: ${e}`); | ||
return; | ||
} | ||
|
||
createNode({ | ||
content, | ||
name: 'Event', | ||
id: 'relay-event', // human-readable ID for referencing in MDX component | ||
parent: null, | ||
children: [], | ||
internal: { | ||
type: `JsonSchema`, | ||
mediaType: 'application/schema+json', | ||
content, | ||
contentDigest: createContentDigest(content), | ||
}, | ||
}); | ||
}; | ||
|
||
|
||
|
||
function quicktypeJSONSchema(targetLanguage, typeName, jsonSchemaString) { | ||
const schemaInput = new JSONSchemaInput(new JSONSchemaStore()); | ||
return schemaInput.addSource({ name: typeName, schema: jsonSchemaString }) | ||
.then(_ => { | ||
const inputData = new InputData(); | ||
inputData.addInput(schemaInput); | ||
|
||
return quicktype({ | ||
inputData, | ||
lang: targetLanguage, | ||
}); | ||
}); | ||
} | ||
|
||
exports.onCreateNode = async ({ actions, createNodeId, node, createContentDigest }) => { | ||
const { createNode, createParentChildLink } = actions; | ||
|
||
if (node.internal.mediaType !== `application/schema+json` || node.internal.type !== `JsonSchema`) { | ||
return; | ||
} | ||
|
||
const { lines } = await quicktypeJSONSchema("markdown", node.name, node.content); | ||
|
||
const child = { | ||
lines, | ||
content: lines.join("\n"), | ||
id: createNodeId(`${node.id}-markdown`), | ||
parent: node.id, | ||
internal: { | ||
content: lines.join("\n"), | ||
mediaType: 'text/markdown', | ||
contentDigest: createContentDigest(lines), | ||
type: `JsonSchemaMarkdown` | ||
} | ||
}; | ||
|
||
createNode(child); | ||
createParentChildLink({ parent: node, child }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
//noop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "gatsby-plugin-jsonschema", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"peerDependencies": { | ||
"gatsby": "^2.0.0" | ||
}, | ||
"dependencies": { | ||
"unist-util-visit": "^1.4.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React from "react" | ||
import { MDXProvider } from "@mdx-js/react"; | ||
import { MDXRenderer } from "gatsby-plugin-mdx"; | ||
import { graphql, useStaticQuery } from "gatsby" | ||
|
||
const JsonSchema = ({id}) => { | ||
// XXX(markus): No clue if this can be replaced by non-static query | ||
// | ||
// This contrived query takes extra care in not referencing allJsonSchema or | ||
// allJsonSchemaMarkdown, as those nodes are not usable if they have not been | ||
// constructed once. That is the case if the data-schema submodule has not | ||
// been checked out in which case we can still show a dummy text instead of | ||
// failing the build. | ||
const query = useStaticQuery(graphql` | ||
{ | ||
allMdx(filter: {parent: {internal: {type: {eq: "JsonSchemaMarkdown"}}}}) { | ||
nodes { | ||
body | ||
parent { | ||
parent { | ||
id | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`); | ||
|
||
const mdxNode = query.allMdx.nodes.find(node => node.parent.parent.id === id); | ||
|
||
if (!mdxNode) { | ||
return "Failed to load JSON Schema. Either the ID you have passed into the component does not exist or you are missing some git submmodules."; | ||
} | ||
|
||
return ( | ||
<MDXProvider> | ||
<MDXRenderer>{mdxNode.body}</MDXRenderer> | ||
</MDXProvider> | ||
); | ||
} | ||
|
||
export default JsonSchema; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule data-schemas
added at
b6d94b
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
title: Event Type Definitions | ||
--- | ||
|
||
This page documents the event schema for errors, just like the other documents | ||
at <Link to="/sdk/event-payloads/">Event Payloads</Link> do. However, the | ||
sections here are automatically generated from code, and because of that they | ||
are more complete and less out of date. We intend to make this page the single | ||
source of truth and replace all the other "interface" pages, but there is still | ||
some work to be done to make this more human-readable. | ||
|
||
Go to [our schemas repo](https://github.com/getsentry/sentry-data-schemas) to | ||
learn more. | ||
|
||
<JsonSchema id="relay-event" /> |
Oops, something went wrong.