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

add typeName option to gatsby-transformer-json #7914

Merged
merged 4 commits into from
Sep 10, 2018

Conversation

eLod
Copy link
Contributor

@eLod eLod commented Sep 6, 2018

see #7670

pieh
pieh previously requested changes Sep 6, 2018
Copy link
Contributor

@pieh pieh left a 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]]) => {
Copy link
Contributor

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)
Copy link
Contributor

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
    })
  })
)

@eLod
Copy link
Contributor Author

eLod commented Sep 6, 2018

sure i can do the code changes. about the documentation: do you have any templates/guides/anything i can follow?

@pieh
Copy link
Contributor

pieh commented Sep 6, 2018

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 fixed typeName and function typeName

@eLod
Copy link
Contributor Author

eLod commented Sep 7, 2018

@pieh added some commits, pls check the docs part, i'm not a native english speaker, let me know if you need anything else

@pieh pieh dismissed their stale review September 7, 2018 12:22

documentation was added

@pieh
Copy link
Contributor

pieh commented Sep 7, 2018

I'm definitely not native speaker too :)

I started to think if maybe we could change signature of typeName function a little bit - so we pass object instead of 3 args:

-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:

      resolve: `gatsby-transformer-json`,
      options: {
        typeName: ((node, object, iDontUseThat, iDontUseThat2, iDontUseThat3, thisIsArgICareAbout) => thisIsArgICareAbout),
      },

with object they could destructure params they want - what ya think?

@eLod
Copy link
Contributor Author

eLod commented Sep 7, 2018

@pieh agreed, pushed

Copy link
Contributor

@pieh pieh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @eLod!

@pieh pieh merged commit 4173eb0 into gatsbyjs:master Sep 10, 2018
wardpeet pushed a commit that referenced this pull request Apr 24, 2019
@theredwillow
Copy link

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.

Missing onError handler for invocation 'extracting-queries', error was 'Error: Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/ but "" does not.

Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/ but "" does not.'. Stacktrace was 'Error: Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/ but "" does not.

Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/ but "" does not.
    at assertValidSchema (/.../node_modules/graphql/type/validate.js:71:11)
    at validate (/.../node_modules/graphql/validation/validate.js:54:35)
    at extractOperations (/.../node_modules/gatsby/src/query/query-compiler.js:212:20)
    at processQueries (/.../node_modules/gatsby/src/query/query-compiler.js:171:45)
    at compile (/.../node_modules/gatsby/src/query/query-compiler.js:82:19)'

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants