Jump to content

GraphQL for ProcessWire


dadish

Recommended Posts

  • 2 weeks later...

Hello !

Thank you for this very nice module @dadish

I'm trying to get the ProField RepeaterMatrix to work based on this fork here by Tulios link.

But I'm having a hard time, struggling for some days deciphering the complex GraphQL architecture and logging everything in the console haha

I really would like to use it like this screenshot below, with fragments for every repeater matrix types.

 

image.png.1d5f91e5f5971e25745556bc1f10268a.png

 

The main issue I have is I can't find a way to build the list of every possible templates types.

The way RepeaterMatrix works is it is differentiating the types based on the repeater_matrix_type. It doesn't seem to work with templates. I tried to use the constructor `new Template()` to create some based on this property but I don't know where to add this line.

Also should I create a new RepeaterMatrixPageArrayType based on your PageArrayType?

Any chance you would take a look? I know it's a ProField, but if you got some time I would be very grateful

  • Like 1
Link to comment
Share on other sites

Hello @Matoseb,

I haven't used any of the pro fields, myself. So I don't know much about them. But conceptually they should be very similar to list of pages.

4 hours ago, Matoseb said:

The way RepeaterMatrix works is it is differentiating the types based on the repeater_matrix_type. It doesn't seem to work with templates. I tried to use the constructor `new Template()` to create some based on this property but I don't know where to add this line.

You should take a closer look what I do in PageType. I create the fields of the page by inspecting it's template. I don't know what kind of API the repeater_matrix_type has, but I suspect similar. But even then, I have a separate type generator for each supported field. If RepeaterMatrix does not use those as underlying FieldType classes, then you'll have to recreate for each of them on your own.

5 hours ago, Matoseb said:

Also should I create a new RepeaterMatrixPageArrayType based on your PageArrayType?

Yes, but the bulk of the work would be implementing the equivalent of PageType that would be responsible for creating types for each repeater_matrix_type. The PageArrayType simply wraps the PageType into an array and adds things like pagination, first item, last item, total count, etc.

5 hours ago, Matoseb said:

Any chance you would take a look? I know it's a ProField, but if you got some time I would be very grateful

Sorry bud. The ProFields are out of the scope of this plugin.

Link to comment
Share on other sites

On 1/2/2022 at 12:55 AM, ngrmm said:

UPDATE: seems it has something to do with my site-settings
I tried it in JS and it works

Glad to see you progressed on this.

On 1/2/2022 at 12:55 AM, ngrmm said:

However when I use /graphql/ as URL i see an object in the console. When I use /processwire/setup/graphql/ I see a json in the console

The /processwire/setup/graphql/ is for internal/admin use only. You should focus on the /graphql/ endpoint.

Link to comment
Share on other sites

Thank you dadish for you infos, that was fast

I'll try again soon!

1 hour ago, dadish said:

I haven't used any of the pro fields, myself. So I don't know much about them. But conceptually they should be very similar to list of pages.

Yes, they are based on the Repeaters. It contains a list of pages of the same template, but with repeater_matrix_type  differentiating the different possible entries.

1 hour ago, dadish said:

I don't know what kind of API the repeater_matrix_type has, but I suspect similar.

The repeater_matrix_type field is a FieldtypeInteger

Link to comment
Share on other sites

Good news !

I managed to add some good support for ProField RepeaterMatrix.

Github link (experimental, use at your own risk!)

Todo

  • Only allow possible fields per matrix types in the schema.
  • Add matrix type as names and not as integers. Easier to read.
  • Support for mutations / inputfields.
  • Repeater Depth/Indents -> Need to add feature to FieldTypeRepeater.

However I can't share it as a third party module. You have to insert the php file manually.

This is due to the static method field() {} not being called from a third party module. Feature request? ?

BTW @dadish I couldn't find a way to add invisible types to the Schema during construction. I tried to use the modifySchema hook, but no luck. Could be useful

  • Like 1
Link to comment
Share on other sites

  • 1 year later...

What is the best way to avoid naming conflicts when querying Option-Select Field with values starting with numbers, which breaks the Schema. This occures when adding the (options) field in the module config screen for fields to serve.

Link to comment
Share on other sites

  • 4 weeks later...

 

On 4/18/2023 at 2:28 PM, martind said:

What is the best way to avoid naming conflicts when querying Option-Select Field with values starting with numbers, which breaks the Schema. This occures when adding the (options) field in the module config screen for fields to serve.

Hey @martind,

So I looked into this and it looks like it's not possible. The values for the FieldtypeOptions are described in Enums. The values for the Enums in GraphQL spec should conform to the GraphQL Name. Which must start with a letter and followed by zero or more letters and/or numbers. So an option in the FieldtypeOptions that starts with or only have digits will not compile properly.

Link to comment
Share on other sites

On 5/14/2023 at 8:36 PM, dadish said:

 

Hey @martind,

So I looked into this and it looks like it's not possible. The values for the FieldtypeOptions are described in Enums. The values for the Enums in GraphQL spec should conform to the GraphQL Name. Which must start with a letter and followed by zero or more letters and/or numbers. So an option in the FieldtypeOptions that starts with or only have digits will not compile properly.

hi dadish,
first of all thank you for this great module, very imposing. I saw the specs, the problem here is, that i have this values and have to provide it over the api for an upcoming expansion step. Isn't it possible to add such fields with a getQueryFields hook instead the modules field configuration? How do you handle such cases for existing sites and data?
thank you and best wishes!
martin

Link to comment
Share on other sites

1 hour ago, martind said:

i have this values and have to provide it over the api for an upcoming expansion step. Isn't it possible to add such fields with a getQueryFields hook instead the modules field configuration? How do you handle such cases for existing sites and data?

Not sure tbh. I would create an alias field. Create the a similar field. If your field is called `options` call the alias field `options_graphql`. Set the same set of options to your alias field, but make sure to have their title be prefixed with some word. So if your options are `1, 2, 3` then have your alias options `gql_1, gql_2, gql_3` or similar. Add the `options_graphql` field into graphql. Then use hooks to synchronize the two fields when page is saved and loaded with `Pages:saveReady` and `Page:loaded` hooks.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...