GraphQL query in PHP without libraries
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
Is it possible to convert an array or an object in PHP to a GraphQL query without importing a library?
I'm hoping for something that works like json_encode does for JSON.
e.g.
$array['products']['edges']['node']['handle'] = true;
$graphql = graphql_encode($array);
echo $graphql; // prints: {products(first: 10) { edges { node { handle }}}}
Maybe this would always be an oversimplification (e.g. I'm not quite sure how "(first: 10)" would be added to the array).
But I'm just looking for a simple way to start experimenting with GraphQL (and I don't have access to SSH or Composer on my shared hosting so it's not easy for me to add the right libraries).
php graphql
|
show 1 more comment
Is it possible to convert an array or an object in PHP to a GraphQL query without importing a library?
I'm hoping for something that works like json_encode does for JSON.
e.g.
$array['products']['edges']['node']['handle'] = true;
$graphql = graphql_encode($array);
echo $graphql; // prints: {products(first: 10) { edges { node { handle }}}}
Maybe this would always be an oversimplification (e.g. I'm not quite sure how "(first: 10)" would be added to the array).
But I'm just looking for a simple way to start experimenting with GraphQL (and I don't have access to SSH or Composer on my shared hosting so it's not easy for me to add the right libraries).
php graphql
1
I would suggest setting up local dev environment with WAMP/LAMP/MAMP to experiment with new stuff. Then you would have full access to all the tools and libs
– Eriks Klotins
Jan 3 at 22:38
The standard GraphQL HTTP interface is fairly simple and if you can make JSON-over-HTTP calls you don't strictly speaking need a GraphQL client library.
– David Maze
Jan 3 at 23:02
@EriksKlotins Thanks, I'm thinking about using my local dev to get the library and then upload via ftp. I'd like to start using it live as soon as possible.
– Andri
Jan 3 at 23:23
@DavidMaze I'm not sure I understand what you mean. If you are suggesting that I just type out the queries, then that's always a possibility, but seems kind of silly to have to do that. That's how I did JSON to begin with, but not the best way when I'm doing something a bit more complicated.
– Andri
Jan 3 at 23:26
Typical GraphQL usage in most languages in fact involves actually writing out the queries. ("Like SQL", if that's a helpful analogy.) A full-featured GraphQL library might have an object model for it but using that tends to be more complex and involves knowing GraphQL in detail anyways.
– David Maze
Jan 3 at 23:52
|
show 1 more comment
Is it possible to convert an array or an object in PHP to a GraphQL query without importing a library?
I'm hoping for something that works like json_encode does for JSON.
e.g.
$array['products']['edges']['node']['handle'] = true;
$graphql = graphql_encode($array);
echo $graphql; // prints: {products(first: 10) { edges { node { handle }}}}
Maybe this would always be an oversimplification (e.g. I'm not quite sure how "(first: 10)" would be added to the array).
But I'm just looking for a simple way to start experimenting with GraphQL (and I don't have access to SSH or Composer on my shared hosting so it's not easy for me to add the right libraries).
php graphql
Is it possible to convert an array or an object in PHP to a GraphQL query without importing a library?
I'm hoping for something that works like json_encode does for JSON.
e.g.
$array['products']['edges']['node']['handle'] = true;
$graphql = graphql_encode($array);
echo $graphql; // prints: {products(first: 10) { edges { node { handle }}}}
Maybe this would always be an oversimplification (e.g. I'm not quite sure how "(first: 10)" would be added to the array).
But I'm just looking for a simple way to start experimenting with GraphQL (and I don't have access to SSH or Composer on my shared hosting so it's not easy for me to add the right libraries).
php graphql
php graphql
asked Jan 3 at 22:33
AndriAndri
13911
13911
1
I would suggest setting up local dev environment with WAMP/LAMP/MAMP to experiment with new stuff. Then you would have full access to all the tools and libs
– Eriks Klotins
Jan 3 at 22:38
The standard GraphQL HTTP interface is fairly simple and if you can make JSON-over-HTTP calls you don't strictly speaking need a GraphQL client library.
– David Maze
Jan 3 at 23:02
@EriksKlotins Thanks, I'm thinking about using my local dev to get the library and then upload via ftp. I'd like to start using it live as soon as possible.
– Andri
Jan 3 at 23:23
@DavidMaze I'm not sure I understand what you mean. If you are suggesting that I just type out the queries, then that's always a possibility, but seems kind of silly to have to do that. That's how I did JSON to begin with, but not the best way when I'm doing something a bit more complicated.
– Andri
Jan 3 at 23:26
Typical GraphQL usage in most languages in fact involves actually writing out the queries. ("Like SQL", if that's a helpful analogy.) A full-featured GraphQL library might have an object model for it but using that tends to be more complex and involves knowing GraphQL in detail anyways.
– David Maze
Jan 3 at 23:52
|
show 1 more comment
1
I would suggest setting up local dev environment with WAMP/LAMP/MAMP to experiment with new stuff. Then you would have full access to all the tools and libs
– Eriks Klotins
Jan 3 at 22:38
The standard GraphQL HTTP interface is fairly simple and if you can make JSON-over-HTTP calls you don't strictly speaking need a GraphQL client library.
– David Maze
Jan 3 at 23:02
@EriksKlotins Thanks, I'm thinking about using my local dev to get the library and then upload via ftp. I'd like to start using it live as soon as possible.
– Andri
Jan 3 at 23:23
@DavidMaze I'm not sure I understand what you mean. If you are suggesting that I just type out the queries, then that's always a possibility, but seems kind of silly to have to do that. That's how I did JSON to begin with, but not the best way when I'm doing something a bit more complicated.
– Andri
Jan 3 at 23:26
Typical GraphQL usage in most languages in fact involves actually writing out the queries. ("Like SQL", if that's a helpful analogy.) A full-featured GraphQL library might have an object model for it but using that tends to be more complex and involves knowing GraphQL in detail anyways.
– David Maze
Jan 3 at 23:52
1
1
I would suggest setting up local dev environment with WAMP/LAMP/MAMP to experiment with new stuff. Then you would have full access to all the tools and libs
– Eriks Klotins
Jan 3 at 22:38
I would suggest setting up local dev environment with WAMP/LAMP/MAMP to experiment with new stuff. Then you would have full access to all the tools and libs
– Eriks Klotins
Jan 3 at 22:38
The standard GraphQL HTTP interface is fairly simple and if you can make JSON-over-HTTP calls you don't strictly speaking need a GraphQL client library.
– David Maze
Jan 3 at 23:02
The standard GraphQL HTTP interface is fairly simple and if you can make JSON-over-HTTP calls you don't strictly speaking need a GraphQL client library.
– David Maze
Jan 3 at 23:02
@EriksKlotins Thanks, I'm thinking about using my local dev to get the library and then upload via ftp. I'd like to start using it live as soon as possible.
– Andri
Jan 3 at 23:23
@EriksKlotins Thanks, I'm thinking about using my local dev to get the library and then upload via ftp. I'd like to start using it live as soon as possible.
– Andri
Jan 3 at 23:23
@DavidMaze I'm not sure I understand what you mean. If you are suggesting that I just type out the queries, then that's always a possibility, but seems kind of silly to have to do that. That's how I did JSON to begin with, but not the best way when I'm doing something a bit more complicated.
– Andri
Jan 3 at 23:26
@DavidMaze I'm not sure I understand what you mean. If you are suggesting that I just type out the queries, then that's always a possibility, but seems kind of silly to have to do that. That's how I did JSON to begin with, but not the best way when I'm doing something a bit more complicated.
– Andri
Jan 3 at 23:26
Typical GraphQL usage in most languages in fact involves actually writing out the queries. ("Like SQL", if that's a helpful analogy.) A full-featured GraphQL library might have an object model for it but using that tends to be more complex and involves knowing GraphQL in detail anyways.
– David Maze
Jan 3 at 23:52
Typical GraphQL usage in most languages in fact involves actually writing out the queries. ("Like SQL", if that's a helpful analogy.) A full-featured GraphQL library might have an object model for it but using that tends to be more complex and involves knowing GraphQL in detail anyways.
– David Maze
Jan 3 at 23:52
|
show 1 more comment
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54030731%2fgraphql-query-in-php-without-libraries%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54030731%2fgraphql-query-in-php-without-libraries%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
I would suggest setting up local dev environment with WAMP/LAMP/MAMP to experiment with new stuff. Then you would have full access to all the tools and libs
– Eriks Klotins
Jan 3 at 22:38
The standard GraphQL HTTP interface is fairly simple and if you can make JSON-over-HTTP calls you don't strictly speaking need a GraphQL client library.
– David Maze
Jan 3 at 23:02
@EriksKlotins Thanks, I'm thinking about using my local dev to get the library and then upload via ftp. I'd like to start using it live as soon as possible.
– Andri
Jan 3 at 23:23
@DavidMaze I'm not sure I understand what you mean. If you are suggesting that I just type out the queries, then that's always a possibility, but seems kind of silly to have to do that. That's how I did JSON to begin with, but not the best way when I'm doing something a bit more complicated.
– Andri
Jan 3 at 23:26
Typical GraphQL usage in most languages in fact involves actually writing out the queries. ("Like SQL", if that's a helpful analogy.) A full-featured GraphQL library might have an object model for it but using that tends to be more complex and involves knowing GraphQL in detail anyways.
– David Maze
Jan 3 at 23:52