dreadjr
05/20/2018, 4:00 PMgraphql
type File {
id: ID! @unique
path: String!
}
schema.graphql
graphql
# import File from "./generated/prisma.graphql"
// I want to extend the application schema to load the file and convert to base64, but don't want to keep in database.
Is this possible?
extend type File {
base64: String
}
or inherit
type ExtendedFile inherits File {
base64: String
}
Do I redefine all the File fields in the schema graphql?Vakrim
05/20/2018, 4:26 PMextend type
with https://www.apollographql.com/docs/graphql-tools/schema-stitching.htmldreadjr
05/20/2018, 5:14 PMnilan
05/22/2018, 1:24 PMschema.graphql
does not affect datamodel.graphql
dreadjr
05/22/2018, 4:06 PMschema.graphql
that aren’t in the underlying database datamodel.graphql
. I think i have achieved this through something like this, Also just redefined File
in the schema.graphql
with the extra field instead of importing it.
js
base64: {
fragment: `fragment Base64 on File { id path }`,
resolve: async ({ path, base64 }, args, ctx, info) => {
if (base64) {
// console.log("already have it base64", parent);
return base64;
}
console.log("getting base64", path);
return await fileToString(path, 'base64');
}
},
Do you think this is a good way to achieve this?nilan
05/22/2018, 4:07 PMnilan
05/22/2018, 4:07 PMfragment:it doesn't look like you'd need,fragment Base64 on File { id path }
id
though, you are not using it anywherenilan
05/22/2018, 4:09 PMfragment
at all, you are not using that path
eitherdreadjr
05/23/2018, 2:06 AM