collective / gatsby-starter-plone

Gatsby starter for Plone
https://collective.github.io/gatsby-starter-plone/
MIT License
4 stars 3 forks source link

Compilation error with local restapi instance #27

Closed bsuttor closed 4 years ago

bsuttor commented 4 years ago

Hi,

I just try this very cool project, but I have some issues when I use a local container instead of plonedemo.kitconcept.com source site.

Here are steps to reproduce:

First I start à local plone restapi instance with a docker-compose.yml file:

version: '3'
services:
  api:
    image: "kitconcept/plone.restapi"
    ports:
      - 8080:8080

$ docker-compose up -d

After I create a gatsby source as explain in doc

$ gatsby new gatsby-restapi https://github.com/collective/gatsby-starter-plone

Then I set source site to use local plone restapi container

$ cd gatsby-restapi 
$ sed -i -e "s/https:\/\/plonedemo.kitconcept.com\/en/http:\/\/localhost:8080\/Plone/g" gatsby-config.js
$ find *.js -exec sed -i "s/frontpage/front-page/g" {} \;

And finaly I start gatsby

$ gatsby develop

And here is trace log with compilations errors

 ERROR #85901  GRAPHQL

There was an error in your GraphQL query:

Cannot query field "allPloneEvent" on type "Query". Did you mean "allPloneSite", "allPloneDocument", "allPloneFolder", "allPloneNavigation", or "allPloneCollection"?                                             

File: gatsby-node.js:11:24

ERROR #85901  GRAPHQL

There was an error in your GraphQL query:

Cannot query field "allPloneNewsItem" on type "Query". Did you mean "allPloneSite", "ploneSite", "allPloneFolder", "allPloneNavigation", or "allPloneDocument"?                                                   

File: gatsby-node.js:11:24
 ERROR #11321  PLUGIN
"gatsby-node.js" threw an error while running the createPages lifecycle:
Cannot read property 'allPloneDocument' of undefined

  TypeError: Cannot read property 'allPloneDocument' of undefined
  - gatsby-node.js:45 Object.exports.createPages
 ERROR  Failed to compile with 1 errors                                                                                                                                                                    
⠀
 error  in ./src/components/RichText.js
⠀
Module Error (from ./node_modules/eslint-loader/index.js):

/projects/gatsby-restapi/src/components/RichText.js
  56:21  error  Unknown type "PloneImage". Did you mean "PloneSite", "PloneSiteEdge", "PloneFolder", "PloneSiteItems", or "PloneSiteTiles"?  graphql/template-strings

✖ 1 problem (1 error, 0 warnings)

Am I doing something wrong to test gatsby-starter-plone with empty Plone site?

datakurre commented 4 years ago
  1. update to the latest gatsby release
  2. configure schema export and import https://github.com/collective/gatsby-source-plone/issues/76#issuecomment-520546243
  3. build the kitconcept site
  4. now switch back to custom site
datakurre commented 4 years ago

So, yes. Empty site does not work unless schemata expected by the project is somehow delivered. Exporting and importing a schema only become possible a few months ago and this starter has not been updated to include schemata.

bsuttor commented 4 years ago

Thank you, In deed, I add this code on the end of gatsby-node.js file:

const fs = require('fs')                                                        
const PLONE_SCHEMA = 'plone-typedefs.graphql'                                   

exports.createSchemaCustomization = ({ actions }) => {                          
  if (fs.existsSync(PLONE_SCHEMA)) {                                            
    actions.createTypes(fs.readFileSync(PLONE_SCHEMA, { encoding: 'utf-8' }));  
  } else {                                                                      
    actions.printTypeDefinitions({                                              
      path: PLONE_SCHEMA,                                           
      include: { plugins: ['gatsby-source-plone'] },                            
    });                                                                         
  }                                                                             
};

After I make gastby develop with https://plonedemo.kitconcept.com/en as baseUrl value (on gastby-config.js file) and finally I can use localhost as baseUrl and start gastby develop one last time.

datakurre commented 4 years ago

@bsuttor Awesome. If you had a change and would be able to contribute that (and the required version upgrades) into this project it would be even more awesome.

bsuttor commented 4 years ago

I was looking to make a PR but I saw you already added plone-typedefs.graphql file and some other update. Thank you ! It works fine now with empty website. I try to add mosaic view (customContentLayout) of a Document now, but I'm not sure what the best way to do that

datakurre commented 4 years ago

You may need to delete typedefs to let them be updated with layout attributes. Unfortunately, the layout is in HTML, so not easily usable. If you would really like to use it, you might need to implement new mosaic-expansion for plone.restapi that e.g. could include HTML for rendered tiles and maybe the layout in JSON (could be done by parsing it with lxml).

I don’t have mosaic support in my timeline currently. Before that I need to try out how Volto layouts and tiles could work (they expose configuration in JSON and would require Volto React-components or their reimplementations for actual rendering).