Skip to content

Commit

Permalink
fix(gatsby-transformer-sharp): define required image fields as non-nu…
Browse files Browse the repository at this point in the history
…ll in schema (#20314)

* Fix schema to represent required image fields

* Improve consistency
  • Loading branch information
daugsbi authored and GatsbyJS Bot committed Jan 8, 2020
1 parent 0360155 commit e3026c9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
17 changes: 9 additions & 8 deletions packages/gatsby-source-contentful/src/extend-node-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const {
GraphQLInt,
GraphQLFloat,
GraphQLJSON,
GraphQLNonNull,
} = require(`gatsby/graphql`)
const qs = require(`qs`)
const base64Img = require(`base64-img`)
Expand Down Expand Up @@ -327,10 +328,10 @@ const fixedNodeType = ({ name, getTracedSVG }) => {
resolve: getTracedSVG,
},
aspectRatio: { type: GraphQLFloat },
width: { type: GraphQLFloat },
height: { type: GraphQLFloat },
src: { type: GraphQLString },
srcSet: { type: GraphQLString },
width: { type: new GraphQLNonNull(GraphQLFloat) },
height: { type: new GraphQLNonNull(GraphQLFloat) },
src: { type: new GraphQLNonNull(GraphQLString) },
srcSet: { type: new GraphQLNonNull(GraphQLString) },
srcWebp: {
type: GraphQLString,
resolve({ image, options, context }) {
Expand Down Expand Up @@ -421,9 +422,9 @@ const fluidNodeType = ({ name, getTracedSVG }) => {
type: GraphQLString,
resolve: getTracedSVG,
},
aspectRatio: { type: GraphQLFloat },
src: { type: GraphQLString },
srcSet: { type: GraphQLString },
aspectRatio: { type: new GraphQLNonNull(GraphQLFloat) },
src: { type: new GraphQLNonNull(GraphQLString) },
srcSet: { type: new GraphQLNonNull(GraphQLString) },
srcWebp: {
type: GraphQLString,
resolve({ image, options, context }) {
Expand Down Expand Up @@ -458,7 +459,7 @@ const fluidNodeType = ({ name, getTracedSVG }) => {
return _.get(fluid, `srcSet`)
},
},
sizes: { type: GraphQLString },
sizes: { type: new GraphQLNonNull(GraphQLString) },
},
}),
args: {
Expand Down
17 changes: 9 additions & 8 deletions packages/gatsby-transformer-sharp/src/customize-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const {
GraphQLString,
GraphQLInt,
GraphQLFloat,
GraphQLNonNull,
} = require(`gatsby/graphql`)
const {
queueImageResizing,
Expand Down Expand Up @@ -73,10 +74,10 @@ const fixedNodeType = ({
}),
},
aspectRatio: { type: GraphQLFloat },
width: { type: GraphQLFloat },
height: { type: GraphQLFloat },
src: { type: GraphQLString },
srcSet: { type: GraphQLString },
width: { type: new GraphQLNonNull(GraphQLFloat) },
height: { type: new GraphQLNonNull(GraphQLFloat) },
src: { type: new GraphQLNonNull(GraphQLString) },
srcSet: { type: new GraphQLNonNull(GraphQLString) },
srcWebp: {
type: GraphQLString,
resolve: ({ file, image, fieldArgs }) => {
Expand Down Expand Up @@ -229,9 +230,9 @@ const fluidNodeType = ({
reporter,
}),
},
aspectRatio: { type: GraphQLFloat },
src: { type: GraphQLString },
srcSet: { type: GraphQLString },
aspectRatio: { type: new GraphQLNonNull(GraphQLFloat) },
src: { type: new GraphQLNonNull(GraphQLString) },
srcSet: { type: new GraphQLNonNull(GraphQLString) },
srcWebp: {
type: GraphQLString,
resolve: ({ file, image, fieldArgs }) => {
Expand Down Expand Up @@ -266,7 +267,7 @@ const fluidNodeType = ({
).then(({ srcSet }) => srcSet)
},
},
sizes: { type: GraphQLString },
sizes: { type: new GraphQLNonNull(GraphQLString) },
originalImg: { type: GraphQLString },
originalName: { type: GraphQLString },
presentationWidth: { type: GraphQLInt },
Expand Down

0 comments on commit e3026c9

Please sign in to comment.