So far it was optional to add implements Node to the type definitions in the schema. Both of the following definitions were fine.
type User {
id: ID! @isUnique
name: String
}
type OtherUser implements Node {
id: ID! @isUnique
name: String
}
Both would result in the same output when copying or downloading that project:
type User implements Node{
id: ID! @isUnique
name: String
}
type OtherUser implements Node {
id: ID! @isUnique
name: String
}
Since we want to enable the usage of resolver types in the types.graphql we now need a way to discern between types that are backed by the database and transient types that are only used by the resolvers. For this we want to introduce the @model directive on the type level. It will be required for all DB backed types (so all your types currently in the types.graphql) and does not take an argument. Types annotated with @model will implement the Node interface and therefore need the unique id field and will have createdAt and updatedAt available even if you don't specify them in your schema. So the only change to the existing types is that they will now require the @model directive.
The resolver types we want to introduce to the types.graphql soon will be identifiable since they do not have the @model directive and also do not need to have an id type.
type DBType @model{
id: ID! @isUnique
name: String
}
type ResolverType {
noIdFieldNeeded: Int
name: String
}
We will require the @model rather soon to lay the groundwork for the introduction of the resolver types afterwards. Upon deploying a schema with types in the types.graphql that do not have a @model directive you will get a schema validation error that the directive is missing. You will also get a schema error if you still use the implements Node, so please remove it everywhere and add @model to all your types in the types.graphql.
This is now deployed.
I've ended up here after trying to follow the _howtographql.com_ tutorial: https://www.howtographql.com/react-apollo/1-getting-started/
I'm new to graphcool and I get this error when doing:
graphcool init --schema https://graphqlbin.com/hn-starter.graphql --name Hackernews
Whoops, something went wrong while creating the project.
The schema is invalid:
The model Link is missing the @model directive. Please add it. See: https://github.com/graphcool/graphcool/issues/817
I guess the hn-starter.graphql is out of date after this change?
Yes, you just have to replace implements Node with @model for each type declared
@emipc @THook thanks! I updated the schema files for HTG 🙂
I understand and approve of this change, but please have a phase of deploy warnings before making a breaking change like this. Migrating to the new format is easy in this case but it could have been a surprise blocker for critical prod issues, which is never good.
In your project folder, create file named hn-starter.graphql. Its contents should be
type Link @model{
id: ID! @isUnique
createdAt: DateTime!
updatedAt: DateTime!
url: String!
description: String!
}
These contents are a very slight modification of the contents of the remote link from the erroring command https://graphqlbin.com/hn-starter.graphql
Modify the command to point to your new file instead of the remote link.
graphcool init --schema ./hn-starter.graphql --name Hackernews
If I already have createdAt and updatedAt in my model, should I leave it as is or not? I can't tell if removing will delete the fields or if they'll be implicitly included by @model.
The createdAt and updatedAt fields are always implicitly included,
adding/removing them from the types.graphql just enables/disables them from
the Schema.
On 20 Oct 2017 7:49 AM, "Jack Moore" notifications@github.com wrote:
If I already have createdAt and updatedAt in my model, should I leave it as
is or not? I can't tell if removing will delete the fields or if they'll be
implicitly included by @model.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/graphcool/graphcool/issues/817#issuecomment-338112229,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABC0lHC847hZee-c8EiHqOBRuqz7-5kLks5suDSEgaJpZM4P5dqn
.
So, I get that you need the @model directive for DB-backed types, but what about 'resolver' types? (I'm getting an error if I don't include @model directive on a type)
You don't need @model for resolver types. Currently, those are configured in a separate document. You can find resolvers in the examples here: https://github.com/graphcool/framework/tree/master/examples
Thanks for the quick reply! Can @model types have attributes whose type are a non-@model type? (i.e. Customer is a @model type with an address: [Address] where Address is a type without the @model directive)
Most helpful comment
I've ended up here after trying to follow the _howtographql.com_ tutorial: https://www.howtographql.com/react-apollo/1-getting-started/
I'm new to graphcool and I get this error when doing:
Whoops, something went wrong while creating the project.
The schema is invalid:
The model
Linkis missing the @model directive. Please add it. See: https://github.com/graphcool/graphcool/issues/817I guess the hn-starter.graphql is out of date after this change?