Skip to content

Commit

Permalink
fix: don't expect application/json type nodes to be files (#8544)
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyward authored and pieh committed Sep 26, 2018
1 parent b52c51f commit cd780aa
Show file tree
Hide file tree
Showing 4 changed files with 290 additions and 104 deletions.
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

0 comments on commit cd780aa

Please sign in to comment.