Open memolipd opened 5 years ago
@memolipd In the meantime until directives are supported, I found a workaround using a custom middleware
const appendCreatedAt = (r, p, a, c, i,) => {
const formatted = new Date().toISOString();
a.createdAt = { formatted };
return r(p, a, c, i);
};
const appendUpdatedAt = (r, p, a, c, i,) => {
const formatted = new Date().toISOString();
a.updatedAt = { formatted };
return r(p, a, c, i);
};
export const autoCreatedAt = {
Query: {},
Mutation: {
// Mapping of resolvers to append argument to
CreatePerson: appendCreatedAt,
},
};
export const autoUpdatedAt = {
Query: {},
Mutation: {
// Mapping of resolvers to append argument to
UpdatePerson: appendUpdatedAt,
},
};
And applying middlewares to schema
import { applyMiddleware } from 'graphql-middleware';
import { autoCreatedAt, autoUpdatedAt } from './middlewares/date';
const schema = makeAugmentedSchema({
typeDefs,
resolvers
});
applyMiddleware(
schema,
autoCreatedAt,
autoUpdatedAt
)
Unfortunately this is far removed from type definitions and all of the auto generated mutations have to be mapped to manually so hopefully @defaultValue support comes soon. #120
@johnymontana any updates on this?
adding a entity level directive eg
@tracked
to add and correctly update acreated
andupdated
timestamp fields.