Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't expect application/json type nodes to be files #8544

Merged
merged 4 commits into from
Sep 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/gatsby-transformer-json/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ arrays of objects and single objects.

`npm install --save gatsby-transformer-json`

You also need to have `gatsby-source-filesystem` installed and configured so it
If you want to transform json files, you also need to have `gatsby-source-filesystem` installed and configured so it
points to your files.

## How to use
Expand Down Expand Up @@ -182,15 +182,15 @@ or a function that receives the following arguments:
[
{
"level": "info",
"message": "hurray",
"message": "hurray"
},
{
"level": "info",
"message": "it works",
"message": "it works"
},
{
"level": "warning",
"message": "look out",
"message": "look out"
}
]
```
Expand All @@ -201,7 +201,7 @@ module.exports = {
{
resolve: `gatsby-transformer-json`,
options: {
typeName: (({ node, object, isArray }) => object.level),
typeName: ({ node, object, isArray }) => object.level,
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Array [
"internal": Object {
"contentDigest": "whatever",
"mediaType": "application/json",
"name": "test",
"type": "File",
},
"name": "nodeName",
"parent": "SOURCE",
Expand All @@ -51,6 +51,55 @@ Array [
]
`;

exports[`Process JSON nodes correctly correctly creates a node from JSON which is a single object and doesn't come from fs 1`] = `
Array [
Array [
Object {
"blue": true,
"children": Array [],
"funny": "yup",
"id": "foo",
"internal": Object {
"contentDigest": "8838e569ae02d98806532310fb2a577a",
"type": "NotFileJson",
},
"parent": "whatever",
},
],
]
`;

exports[`Process JSON nodes correctly correctly creates a node from JSON which is a single object and doesn't come from fs 2`] = `
Array [
Array [
Object {
"child": Object {
"blue": true,
"children": Array [],
"funny": "yup",
"id": "foo",
"internal": Object {
"contentDigest": "8838e569ae02d98806532310fb2a577a",
"type": "NotFileJson",
},
"parent": "whatever",
},
"parent": Object {
"children": Array [],
"content": "{\\"id\\":\\"foo\\",\\"blue\\":true,\\"funny\\":\\"yup\\"}",
"id": "whatever",
"internal": Object {
"contentDigest": "whatever",
"mediaType": "application/json",
"type": "NotFile",
},
"parent": "SOURCE",
},
},
],
]
`;

exports[`Process JSON nodes correctly correctly creates nodes from JSON which is an array of objects 1`] = `
Array [
Array [
Expand Down Expand Up @@ -100,11 +149,12 @@ Array [
"parent": Object {
"children": Array [],
"content": "[{\\"id\\":\\"foo\\",\\"blue\\":true,\\"funny\\":\\"yup\\"},{\\"blue\\":false,\\"funny\\":\\"nope\\"}]",
"dir": "/tmp/foo/",
"id": "whatever",
"internal": Object {
"contentDigest": "whatever",
"mediaType": "application/json",
"name": "test",
"type": "File",
},
"name": "nodeName",
"parent": "SOURCE",
Expand All @@ -127,11 +177,12 @@ Array [
"parent": Object {
"children": Array [],
"content": "[{\\"id\\":\\"foo\\",\\"blue\\":true,\\"funny\\":\\"yup\\"},{\\"blue\\":false,\\"funny\\":\\"nope\\"}]",
"dir": "/tmp/foo/",
"id": "whatever",
"internal": Object {
"contentDigest": "whatever",
"mediaType": "application/json",
"name": "test",
"type": "File",
},
"name": "nodeName",
"parent": "SOURCE",
Expand All @@ -140,3 +191,91 @@ Array [
],
]
`;

exports[`Process JSON nodes correctly correctly creates nodes from JSON which is an array of objects and doesn't come from fs 1`] = `
Array [
Array [
Object {
"blue": true,
"children": Array [],
"funny": "yup",
"id": "foo",
"internal": Object {
"contentDigest": "8838e569ae02d98806532310fb2a577a",
"type": "NotFileJson",
},
"parent": "whatever",
},
],
Array [
Object {
"blue": false,
"children": Array [],
"funny": "nope",
"id": "uuid-from-gatsby",
"internal": Object {
"contentDigest": "f624311d932d73dcd416d2a8bea2b67d",
"type": "NotFileJson",
},
"parent": "whatever",
},
],
]
`;

exports[`Process JSON nodes correctly correctly creates nodes from JSON which is an array of objects and doesn't come from fs 2`] = `
Array [
Array [
Object {
"child": Object {
"blue": true,
"children": Array [],
"funny": "yup",
"id": "foo",
"internal": Object {
"contentDigest": "8838e569ae02d98806532310fb2a577a",
"type": "NotFileJson",
},
"parent": "whatever",
},
"parent": Object {
"children": Array [],
"content": "[{\\"id\\":\\"foo\\",\\"blue\\":true,\\"funny\\":\\"yup\\"},{\\"blue\\":false,\\"funny\\":\\"nope\\"}]",
"id": "whatever",
"internal": Object {
"contentDigest": "whatever",
"mediaType": "application/json",
"type": "NotFile",
},
"parent": "SOURCE",
},
},
],
Array [
Object {
"child": Object {
"blue": false,
"children": Array [],
"funny": "nope",
"id": "uuid-from-gatsby",
"internal": Object {
"contentDigest": "f624311d932d73dcd416d2a8bea2b67d",
"type": "NotFileJson",
},
"parent": "whatever",
},
"parent": Object {
"children": Array [],
"content": "[{\\"id\\":\\"foo\\",\\"blue\\":true,\\"funny\\":\\"yup\\"},{\\"blue\\":false,\\"funny\\":\\"nope\\"}]",
"id": "whatever",
"internal": Object {
"contentDigest": "whatever",
"mediaType": "application/json",
"type": "NotFile",
},
"parent": "SOURCE",
},
},
],
]
`;
Loading