-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
add typeName option to gatsby-transformer-json #7914
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check inline comments - they are not required, but would make code more maintainable.
Main blocker would be missing documentation of typeName
config option
[null, [`NodeNameJson`, `NodeNameJson`]], | ||
[`fixed`, [`fixed`, `fixed`]], | ||
[((node, obj) => obj.funny), [`yup`, `nope`]], | ||
].forEach(async ([typeName, [expectedOne, expectedTwo]]) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could You convert input data to something that's more readable - for example:
const fixtures = [
{
typeName: null,
exptectedNodeTypes: [`NodeNameJson`, `NodeNameJson`],
}, {
// rest of input data
]
typeName, | ||
}).then(() => { | ||
expect(createNode.mock.calls[0][0].internal.type).toEqual(expectedOne) | ||
expect(createNode.mock.calls[1][0].internal.type).toEqual(expectedTwo) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be changed to use more of jest api instead of relying on jest internals:
expect(createNode).toBeCalledWith(
expect.objectContaining({
internal: expect.objectContaining({
type: expectedOne
})
})
)
sure i can do the code changes. about the documentation: do you have any templates/guides/anything i can follow? |
We usually document that in package README files - for example contentful plugin have "configuration option" section https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-source-contentful#configuration-options - it might be fine to add section like that and probably additional section below with examples of |
@pieh added some commits, pls check the docs part, i'm not a native english speaker, let me know if you need anything else |
I'm definitely not native speaker too :) I started to think if maybe we could change signature of -getType(node, obj, true)
+getType({node, obj, isArray:true}) reason for that: if people will want to add more args in future to this function this might become quite long list of args and using that start looking like that in gatsby-config:
with object they could destructure params they want - what ya think? |
@pieh agreed, pushed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @eLod!
see #7914 for json transformer
I thought it would do this. But it doesn't seem to do anything at all. What is this? I was hoping to use this functionality to override the gatsby extracting-queries error that occurs with improperly named files.
I have files that I download from another application regularly. I suppose I could create a npm script to convert the filenames before the build, but that seems to kinda defeat the purpose of using Gatsby as the generator. Is there a way to do this? |
see #7670