Bluetooth 5: Höhere Geschwindigkeit oder mehr Reichweite

heise online Newsticker - 16. August 2017 - 13:30
Insbesondere fürs Internet der Dinge hat die SIG den neuen Standard Bluetooth 5 entworfen. Dabei sollen Nutzer von einer höheren Geschwindigkeit oder mehr Reichweite profitieren – aber nicht beidem auf einmal.

Cross-Plattform-Entwicklung: Qt adressiert den Automatisierungssektor

heise online Newsticker - 16. August 2017 - 13:30
Die Suite Qt for Automation zielt auf Anwendungen im Bereich Internet der Dinge beziehungsweise Industrie 4.0. Sie setzt auf Qt 5.9 auf und bringt zusätzliche Bibliotheken, unter anderem zur Implementierung des IoT-Protokolls MQTT.

Pokémon Go: Exklusive Raid-Kämpfe gegen Mewtu

heise online Newsticker - 16. August 2017 - 13:00
Niantic entlässt das nächste legendäre Pokémon ins Spiel: Demnächst taucht Mewtu als Gegner auf – doch nicht alle Spieler können ohne weiteres gegen es kämpfen.

Amazee Labs: Extending GraphQL: Part 1 - Fields

Planet Drupal - 16. August 2017 - 12:36
Extending GraphQL: Part 1 - Fields

The last blog post might have left you wondering: "Plugins? It already does everything!". Or you are like one of the busy contributors and already identified a missing feature and can't wait to take the matter into your own hands (good choice).

In this and the following posts we will walk you through the extension capabilities of the GraphQL Core module and use some simple examples to show you how to solve common use cases.

Philipp Melab Wed, 08/16/2017 - 12:36

I will assume that you are already familiar with developing Drupal modules and have some basic knowledge of the Plugin API and Plugin Annotations.

The first thing you will want to do is disabling GraphQL schema and result caches. Add these parameters to your development.services.yml:

parameters: graphql.config: result_cache: false schema_cache: false

This will make sure you don't have to clear caches with every change.

As a starting point, we create an empty module called graphql_example. In the GitHub repository for this tutorial, you will find the end result as well as commits for every major step.

Diff: The module boilerplate

A simple page title field

Can't be too hard, right? We just want to be able to ask the GraphQL API what our page title is.
To do that we create a new class PageTitle in the appropriate plugin namespace Drupal\graphql_example\Plugin\GraphQL\Fields.

Let's talk this through. We've created a new derivation of FieldPluginBase, the abstract base class provided by the graphql_core module.

It already does the heavy lifting for integrating our field into the schema. It does this based on the meta information we put into the annotation:

  • id: A unique id for this plugin.
  • type: The return type GraphQL will expect.
  • name: The name we will use to invoke the field.
  • nullable: Defines if the field can return null values or not.
  • multi: Defines if the field will return a list of values.

Now, all we need to do is implement resolveValues to actually return a field value. Note that this method expects you to use the yield keyword instead of return and therefore return a generator.

Fields also can return multiple values, but the framework already handles this within GraphQL type definitions. So all we do is yield as many values as we want. For single value fields, the first one will be chosen.

So we run the first GraphQL query against our custom field.

query { pageTitle }

And the result is disappointing.

{ "data": { "pageTitle": null } }

Diff: The naive approach

The page title is always null because we extract the page title of the current page, which is the GraphQL API callback and has no title. We then need a way to tell it which page we are talking about.

Adding a path argument

Lucky us, GraphQL fields also can accept arguments. We can use them to pass the path of a page and get the title for real. To do that, we add a new annotation property called arguments. This is a map of argument names to the argument type. In our case, we added one argument with name path that expects a String value.

Any arguments will be passed into our resolveValues method with the $args parameter. So we can use the value there to ask the Drupal route matcher to resolve the route and create the proper title for this path.

Let's try again.

query { pageTitle(path: "/admin") }

Way better:

{ "data": { "pageTitle": "Administration" } }

Congratulations, MVP satisfied - you can go home now!

Diff: Using arguments

If there wasn't this itch every developer has when the engineering senses start to tingle. Last time we stumbled on this ominous route field that also takes a path argument. And this ...

query { pageTitle(path: "/node/1") route(path: "/node/1") { ... } }

... smells like a low hanging fruit. There has to be a way to make the two of them work together.

Attaching fields to types

Every GraphQL field can be attached to one or more types by adding the types property to its annotation. In fact, if the property is omitted, it will default to the Root type which is the root query type and the reason our field appeared there in the first place.

We learned that the route field returns a value of type Url. So we remove the argument definition and add a types property instead.

This means the $args parameter won't receive the path value anymore. Instead, the $value parameter will be populated with the result of the route field. And this is a Drupal Url object that we already can be sure is routed since route won't return it otherwise. With this in mind, we can make the solution even simpler.

Now we have to adapt our query since our field is nested within another.

query { route(path: "/admin") { pageTitle } }

Which also will return a nested result.

{ "data": { "route": { "pageTitle": "Administration" } } }

The price of a more complex nested result might seem high for not having to pass the same argument twice. But there's more to what we just did. By attaching the pageTitle field to the Url type, we added it wherever the type appears. Apart from the route field this also includes link fields, menu items or breadcrumbs. And potentially every future field that will return objects of type Url.
We just turned our simple example into the Swiss Army Knife (pun intended) of page title querying.

Diff: Contextual fields

I know what you are thinking. Even an achievement of this epic scale is worthless without test coverage. And you are right. Let's add some.

Adding tests

Fortunately the GraphQL module already comes with an easy to use test base class that helps us to safeguard our achievement in no time.

First, create a tests directory in the module folder. Inside that, a directory called queries that contains one file - page_title.gql - with our test query. A lot of editors already support GraphQL files with syntax highlighting and autocompletion, that's why we moved the query payload to another file.

The test itself just has to extend GraphQLFileTestBase, add the graphql_example module to the list of modules to enable and execute the query file.

Diff: Adding a test

Wrap-Up

We just created a simple field, passed arguments to it, learned how to attach it to an already existing type and finally verified our work by adding a test case. Not bad for one day's work. Next time we will have a look at Types and Interfaces, and how to use them to create fields with complex results.

Internetsucht: Chinesischer Teenager stirbt in Bootcamp

heise online Newsticker - 16. August 2017 - 12:30
Ratlose Eltern schickten ihren Sohn in ein Bootcamp im chinesischen Fuyang, um seine Internetabhängigkeit zu kurieren. Dort starb er – vermutlich an Misshandlungen, die laut Kritikern zum normalen Erziehungs-Repertoire solcher Einrichtungen zählen.

iPhone 8: Telekom bietet wieder Reservierung an

heise online Newsticker - 16. August 2017 - 12:30
Mit dem Reservierungs-Service will der Netzbetreiber schon frühzeitig das Interesse an Apples 2017er iPhones ausloten. Kunden sollen "bevorzugt" beliefert werden.

ADCI Solutions: New employee adaptation

Planet Drupal - 16. August 2017 - 12:15

What makes any web development team strong? Right, it's people who are the most important part of the success. So, how to shape a great team member out of a newbie?

Here is a small note on how an integration process is set in our Drupal team. We will guide you through all the stages: from an interview to team-building events.

 

Check out if you included all essential adaptation steps into your workflow.

 

 

 

Apples HyperCard wird 30: Viele Stacks per Browser zugänglich

heise online Newsticker - 16. August 2017 - 12:00
Zum 30. Jubiläum der Programmierumgebung für Classic Mac OS hat das Internet Archive zahlreiche HyperCard-Stacks gesammelt, die sich nun im Browser ausführen lassen.

EU-US Privacy Shield: Beschwerdeformulare für Betroffene veröffentlicht

heise online Newsticker - 16. August 2017 - 11:30
Das seit August 2016 geltende Abkommen für die Übermittlung personenbezogener zwischen der EU und den USA räumt Betroffenen verschiedene Rechte sowie Beschwerdemöglichkeiten ein. Die passenden Formulare gibt es online.

Apple-Milliarden: Irland fürchtet sich vor Verlusten

heise online Newsticker - 16. August 2017 - 11:00
Mindestens 13 Milliarden Euro muss das kleine Land bunkern, während das Berufungsverfahren im Steuerstreit mit der Europäischen Kommission läuft. Nun versucht Irland, sich gegen ein eventuelles Investmentminus abzusichern.

Bitcoin-Höhenflug hält an: Kurs nun über 4000 US-Dollar

heise online Newsticker - 16. August 2017 - 11:00
Nicht einmal zwei Wochen nachdem der Kurs des Bitcoin zum ersten Mal über 3000 US-Dollar gestiegen ist, wurde nun schon der nächste Meilenstein erreicht. Der Kurs liegt jetzt schon deutlich über 4000 US-Dollar. Wie es weitergeht, ist unklar.

AMD Radeon RX Vega 64 und 56 angetestet: Rückstand verkürzt, heiß erkauft

heise online Newsticker - 16. August 2017 - 11:00
Die Radeon RX Vega 64 gelangt am heutigen Montag für 500 Euro in den Handel. Erste Testergebnisse zeigen: Trotz hoher Rechenleistung kann AMD nur zu Nvidia aufholen, aber nicht überholen. Der Preis: Eine hohe Leistungsaufnahme.

Elektroautos: Porsche entwickelt Schnell-Ladesäulen

heise online Newsticker - 16. August 2017 - 11:00
2019 soll der erste Elektro-Porsche auf den Markt kommen. Mit der Infrastruktur, die nun entwickelt wird, würde er schneller laden als die Konkurrenz.

Datenbank-Server PostgreSQL: Lücke lässt Anmeldung ohne Passwort zu

heise online Newsticker - 16. August 2017 - 11:00
Administratoren, die PostgreSQL-Datenbanken betreiben, sollten ihre Software updaten. Unter bestimmten Umständen können sich Angreifer an den Servern ohne Eingabe eines Passwortes anmelden, warnen die Entwickler.

Janez Urevc: Call for help with Media source plugin porting

Planet Drupal - 16. August 2017 - 10:42
Call for help with Media source plugin porting slashrsm Wed, 16.08.2017 - 10:42

As you may already know Media entity module entered Drupal 8.4 as Media module earlier this year. This was the result of years of hard work in contrib and core space. While the module stayed conceptually the same we used this opportunity to clean it up and refactor some things; mostly to make APIs even easier to understand and use.

Media entity comes with the concept of so-called source plugins (also called type plugins in the past). They are responsible for everything related to a specific media type: they have knowledge about their nature, about the way they should be stored and displayed, they are aware of any business logic related to them, etc.

There were many plugins already available before Drupal core decided to adopt the module and they mostly lived as separate modules in contrib space. Since the API changed a bit during the core transition all this plugins need to be updated. The process is pretty straightforward, but the number of modules that need to be worked on is quite high. This means that we'll need quite some help from the community to do this as fast and as effectively as possible.

Here is where you come in!

Are you interested in contributing but don't know how? Are you looking for a task that is relatively simple but not completely trivial? Then the porting of media source plugins might be a really good entry point for you!

There is a meta issue that is trying to keep the overview over the porting process. You will find the list of modules and their current status in it. In order to get familiar with the changes that were introduced during the core transition you should check the relevant change record. All information that is needed for ports should be available there. If you'd rather work with examples then take a look at Media entity image and Media entity document, which were adopted to core as Image and File source plugins respectively.

When you decided which module deserves your attention check its issue queue. If there is already an issue about the porting get involved there. If there is not create one to let others know that you are working on the port. In any case make sure to add its reference to the meta overview issue. This will help us to keep the general overview over the process.

Need help?

Have you checked all the resources I mentioned above and you feel that there are still things that are not entirely clear? Come to the #drupal-media channel on IRC. We are hanging out in that channel most of the times. Our weekly meetings happen in the same channel every Wednesday at 14h UTC.

Enjoyed this post? There is more! Results of the Drupal 8 media sprint Call for Drupal 8 media ecosystem co-maintainers Presentations about various Drupal 8 media modules

iX-Workshop zu OpenStack und Docker: noch eine Woche Frühbucherrabatt

heise online Newsticker - 16. August 2017 - 10:30
Wer Docker einsetzt, erledigt die Cloud-Integration oft mit OpenStack. Wie man die beiden Softwarepakete integriert, zeigt ein iX-Workshop am 4./5. Oktober in Nürnberg.

HTTP-Status 418 "Ich bin eine Teekanne" darf bleiben

heise online Newsticker - 16. August 2017 - 10:00
Der HTTP-Statuscode 418 "I'm a tea pot" war eigentlich als Aprilscherz gedacht und drohte, aus dem Netz zu verschwinden. Doch nun könnte der sinnlose Fehlercode sogar zum offiziellen IETF-Standard werden.

Gefährliche SSH-Befehle: Kritische Sicherheitslücke in GitLab

heise online Newsticker - 16. August 2017 - 10:00
Viele Versionskontrollsysteme haben eine Sicherheitslücke, die es Angreifern ermöglicht, Schadcode auszuführen. Beim Webfrontend GitLab ist dies besonders brisant. Admins sollten Installationen der Software umgehend aktualisieren.

Dank Tochter-Firma: Facebook analysiert Nutzungsdaten der Konkurrenz

heise online Newsticker - 16. August 2017 - 9:30
Dank einer vor einigen Jahren übernommenen Firma haben Facebook-Mitarbeiter einem Bericht zufolge Zugriff auf wertvolle Nutzungsdaten anderer App-Anbieter. So kann der Konzern die Konkurrenz analysieren und sich diese vom Leib halten.