Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete image from CMS admin breaks GraphQL queries #7186

Open
smarcet opened this issue Apr 20, 2024 · 3 comments · May be fixed by #7310
Open

Delete image from CMS admin breaks GraphQL queries #7186

smarcet opened this issue Apr 20, 2024 · 3 comments · May be fixed by #7310
Labels
type: bug code to address defects in shipped code

Comments

@smarcet
Copy link

smarcet commented Apr 20, 2024

Hello
i created a simple image field at cms
when i deleted the image from cms admin
its sets to empty on my json file
{ image:"} and start to got this error message
Field "image" must not have a selection since type "String" has no subfields Please replace with a clear and descriptive title
from graphql queries at page
there is a way to tell the widget to remove the field from json file

i already have the custom type defined
gastby-node.js

at exports.createSchemaCustomization
like this

type MemberCompanyNode {
    id: String
    big_logo: String
    name: String
  }
  
  type CompanyNode {
    image: File @fileByRelativePath
    paragraph1: String
    paragraph2: String
    link: String
    memberCompany: MemberCompanyNode
  }
  
  type OSFMemberNode {
    osfMember: CompanyNode
  }
  
  type MemberSpotLiteSectionJson implements Node {
    companies: [OSFMemberNode]
  }

and graphql query at page is

 memberSpotliteSectionJson {
    companies {
      osfMember {
        image {
          publicURL
        }
        link
        memberCompany {
          big_logo
        }
        paragraph1
        paragraph2
      }
    }
  }

also i tried to create a custom resolver
at gastby node.js
exports.createResolvers


createResolvers({
 
    MemberSpotliteSectionJsonCompaniesOsfMember: {
      image: {
        type: "File",
        resolve: (source) => {
          console.log(`MemberSpotliteSectionJsonCompaniesOsfMember`,source.image)
          (source?.image?.publicURL ? source.image : {publicURL:null})
        },
      },
    },
  });

but i got warn `createResolvers` passed resolvers for field `MemberSpotliteSectionJsonCompaniesOsfMember.image` with type `File`. Such a field with type `String` already exists on the type. Use `createTypes` to override type
fields.

really i am stuck at this
there is no simple way to delete an image at CMS and keep it working ?
much thanks

@smarcet smarcet added the type: bug code to address defects in shipped code label Apr 20, 2024
@smarcet smarcet changed the title Field "image" must not have a selection since type "String" has no subfields Please replace with a clear and descriptive title Delete image from CMS admin breaks GraphQL queries Apr 20, 2024
@tizzle
Copy link

tizzle commented May 21, 2024

Same here,

for me this is a rather big problem. I would appreciate a fix for this on CMS side.

Can the team acknowledge this and probably hint at how we can get this fixed?

@tizzle
Copy link

tizzle commented May 21, 2024

also related to #7120

@smarcet
Copy link
Author

smarcet commented May 21, 2024

i ended up with a work around
exports.createResolvers = ({ createResolvers, pathPrefix }) => {
const resolvers = {
MemberSpotliteSectionJsonCompanies: {
companyImagePublicURL: {
type: "String",
resolve: async (source, args, context) => {
console.log("createResolvers", source);
const node = await context.nodeModel.findOne({
query: {
filter: {
base: { eq: source?.image },
},
},
type: "File",
});
console.log("createResolvers entries", node);
if (!node) return source.memberCompany.big_logo;

      const { absolutePath } = node;
      const { ext, name } = path.parse(absolutePath);
      const filename = `${name}--${node.internal.contentDigest}${ext}`;
      const newPath = path.join(publicStaticDir, filename);

      try {
        const exists = await fs.exists(newPath);
        if (!exists) await fs.copy(absolutePath, newPath);
        return `${pathPrefix}/static/${filename}`;
      } catch (e) {
        console.error(
          `error copying file from ${absolutePath} to ${newPath}`,
          e,
        );
      }
      return source.memberCompany.big_logo;
    },
  },
},

};
createResolvers(resolvers);
};

hip3r added a commit to poslovnimediji/decap-cms that referenced this issue Oct 22, 2024
@hip3r hip3r linked a pull request Oct 22, 2024 that will close this issue
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug code to address defects in shipped code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants