Ran
./node_modules/relay-compiler/bin/relay-compiler --schema ./server/graphql/schema.graphql --src ./client --out ./client
First error:
Writing default
Error: You supplied a GraphQL document with validation errors:
Fragment "AlcoholForm_recipientBirthDate" cannot condition on non composite type "Cart".
Field "recipientBirthDate" of type "String" must have a selection of subfields. Did you mean "recipientBirthDate { ... }"?
GraphQL Schema
type Cart {
# The ID of an object
id: ID!
totalNumberOfItems: Int,
recipientBirthDate: String
input CartUpdateRecipientBirthDateInput {
recipientBirthDate: String!
clientMutationId: String
}
AlcoholForm container
export default createFragmentContainer(
AlcoholForm,
graphql`
fragment AlcoholForm_recipientBirthDate on Cart {
recipientBirthDate
}
`
)
I expected Cart to be a composite type because its an object. It seems odd that relay-compiler is asking for subfields when "recipientBirthDate" is a string.
Second error:
Writing default
Error: Can only create NonNull of a Nullable GraphQLType but got: CartUpdateRecipientBirthDateInput.
Mutation
export const CartUpdateRecipientBirthDateMutation = graphql`
mutation CartUpdateRecipientBirthDateMutation(
$input: CartUpdateRecipientBirthDateInput!
) {
cartUpdateRecipientBirthDate(input: $input) {
recipientBirthDate
}
}
`;
I ran the mutation in GraphiQL and it worked fine.
I'm not sure if these are bugs, or I fibbed my queries.
Let me know if you need more information.
This is due to the change in isLeafType() if you downgrade the graphql-js package to 0.9.1 it should work or wait for a new alpha release of Relay with https://github.com/facebook/relay/pull/1611 merged
If you make the field nullable in the schema it should work with 0.9.2 though.
Thanks for giving the compiler an early try and finding this case. Internally, we don't use non-nullable types a lot so we missed this case so far.
[email protected] on my app. Not sure if this will affect relay-compiler because the package.json for relay-compiler and relay is on [email protected]relay-compiler .bin file. This might not have the same result as building the .bin file because [email protected] isn't packaged with it. Still using [email protected]GraphQL schema now looks like
input CartUpdateRecipientBirthDateInput {
recipientBirthDate: String
clientMutationId: String
}
type Cart {
# The ID of an object
id: ID!
recipientBirthDate: String
}
Left the mutation untouched:
import { graphql } from 'react-relay/compat';
export const CartUpdateRecipientBirthDateMutation = graphql`
mutation CartUpdateRecipientBirthDateMutation(
$input: CartUpdateRecipientBirthDateInput!
) {
cartUpdateRecipientBirthDate(input: $input) {
recipientBirthDate
}
}
`;
Running the relay-compiler bin gets the same error:
Error: Can only create NonNull of a Nullable GraphQLType but got: CartUpdateRecipientBirthDateInput.
Package versions:
[email protected][email protected] w/ fix-leaf-type changes manually put in the bin fileIs there something I'm not making nullable?
The only thing I can think of is changing the mutation:
import { graphql } from 'react-relay/compat';
export const CartUpdateRecipientBirthDateMutation = graphql`
mutation CartUpdateRecipientBirthDateMutation(
$input: CartUpdateRecipientBirthDateInput
) {
cartUpdateRecipientBirthDate(input: $input) {
recipientBirthDate
}
}
`;
Which gets me:
Writing default
Error: You supplied a GraphQL document with validation errors:
Variable "$input" cannot be non-input type "CartUpdateRecipientBirthDateInput".
Field "recipientBirthDate" of type "String" must have a selection of subfields. Did you mean "recipientBirthDate { ... }"?
Is it possible that two versions of graphql-js end up getting installed somehow? The compiler uses instanceof checks in many places, and if two versions are installed they can fail.
Fix for the leaf type issue: https://github.com/facebook/relay/pull/1611
I am still getting the same issue after building the compiler on master after @leebyron's fix.
It happens after trying to port one component to the modern API and running the compiler.
Fragment declaration:
export default createFragmentContainer(CoffeeShopCell, {
coffeeShop: graphql`
fragment CoffeeShopCell_coffeeShop on CoffeeShop {
id
name
}
`,
}),
Schema:
# An object with an ID
interface Node {
# The id of the object.
id: ID!
}
type CoffeeShop implements Node {
# The ID of an object
id: ID!
name: String
}
Error:
Fragment "CoffeeShopCell_coffeeShop" cannot condition on non composite type "Cof
feeShop".
Field "id" of type "ID!" must have a selection of subfields. Did you mean "id {
... }"?
Field "name" of type "String" must have a selection of subfields. Did you mean "
name { ... }"?
@josephsavona Looks like you are right about instanceof checks.


I'm seeing this on the latest release
Tested #1617 and it does work now!
Can confirm alpha 4 fixes this :)
Most helpful comment
Tested #1617 and it does work now!