Exactly! Regular readers of this blog (me) will appreciate my stumbling attempts to pre-define a REST interface that supports many-to-many interfaces. GET a class, for example, and the return includes an array of the students in that class. In this context, we don't want a full Student record, just the Student's name and Id, for example.
With a REST interface, the server writer has to guess how to abbreviate the Student record. GraphQL fixes that. The front end requests just the data it wants. If we want a list of the students in a class and the assigned roommates for that student...we can do that!
A lot of my prototype REST service is hardwired--not single tables, so much, but the many-to-many stuff certainly. There was a certain amount of work implementing the simple router ("/table/recordno").
GraphQL means throwing a lot of that away, but I can see immediately that GraphQL's approach is what I want. My schema tables (implementing INSERT and UPDATE) look a lot like GraphQL:
I don't know where GraphQL is "at" yet, but maybe I could contribute. There's graphql-php, and a library called graphql-relay-php that supports react-relay (whatever that is). Siler is a PHP library powered with high-level sbstractions to work with GraphQL.
Composer is a php dependency manager, not a package manager like npm, but sort of. Installing Composer put php on my system PATH, so that's something.
With a REST interface, the server writer has to guess how to abbreviate the Student record. GraphQL fixes that. The front end requests just the data it wants. If we want a list of the students in a class and the assigned roommates for that student...we can do that!
A lot of my prototype REST service is hardwired--not single tables, so much, but the many-to-many stuff certainly. There was a certain amount of work implementing the simple router ("/table/recordno").
GraphQL means throwing a lot of that away, but I can see immediately that GraphQL's approach is what I want. My schema tables (implementing INSERT and UPDATE) look a lot like GraphQL:
type Query {
hero: Character
}
type Character {
name: String
friends: [Character]
homeWorld: Planet
species: Species
}
type Planet {
name: String
climate: String
}
type Species {
name: String
lifespan: Int
origin: Planet
}
I don't know where GraphQL is "at" yet, but maybe I could contribute. There's graphql-php, and a library called graphql-relay-php that supports react-relay (whatever that is). Siler is a PHP library powered with high-level sbstractions to work with GraphQL.
Getting Started
So, I downloaded graphql-php from github. Github doesn't like my old password, and 1Password doesn't like Chrome for some reason, so that took a while to sort. The graphql-php library is documented in Markdown, so I got a Markdown viewer. Eh. Turns out, the library instructions start with composer, so I had to download that.Composer is a php dependency manager, not a package manager like npm, but sort of. Installing Composer put php on my system PATH, so that's something.
Comments
Post a Comment